3

Trying to change the title of a current gnome-terminal (similar to the "set title" that you can do manually")

The system is running Fedora 9. The HowTo Xterm-Title discusses how to set the prompt, for an xterm. Tried to implement the escape sequences with no luck. (might be something weird..)

Tried to use the gconftool to dump/change/load the changed conf attributes, and again, no luck. Also, set the PROMPT_COMMAND just in case the prompt command was somehow changing the title back (which is highly doubtful)

Searching the 'net indicates that a few people have tried to solve this with no luck...

I'd also like to figure out how to create a new gnome-terminal with a unique specified title...

once this is solved, i'l gladly create a quick writeup/post onn how to accomplish this for others...

thanks

8 Answers8

4

To change the title of the current window :

wmctrl -r :ACTIVE: -N "MyWindowTitle"
Falcon Momot
  • 24,975
  • 13
  • 61
  • 92
metatechbe
  • 141
  • 4
4

Take a look at your /etc/bashrc (or equivalent). Modern Linux distributions have this already in place - you just may have to enable it.

For instance, on openSuSE, it's handled by a bash function:

ppwd () 
{ 
    local _t="$1" _w _x _u="$USER" _h="$HOST";
    test -n "$_t" || return;
    test "${_t#tty}" = $_t && _t=pts/$_t;
    test -O /dev/$_t || return;
    _w="$(dirs +0)";
    _x=$((${#_w}-18));
    test ${#_w} -le 18 || _w="...${_w#$(printf "%.*s" $_x "$_w")}";
    printf "\e]2;%s@%s:%s\007\e]1;%s\007" "$_u" "$_h" "$_w" "$_h" > /dev/$_t
}

and my PS1 is:

$(ppwd \l)\u@\h:\w>

This causes my xterm & gnome-terminal title to be set to user@host:/smartpath every time the prompt is displayed.

If you're read this far, you should know that the easy way to set the title one time is:

echo -e '\e]2;Title Text\007\e]1;\007'
MikeyB
  • 38,725
  • 10
  • 102
  • 186
1
gnome-terminal --title="My New Terminal" &

Can launch into an infinite spawning of terminal processes which will take your machine down. Remove that users post.

Try this instead

printf '\033]0;SOME TITLE HERE\007' #set Terminal title
bjoster
  • 4,423
  • 5
  • 22
  • 32
1

I got the title changing working in a script with the help of xtitle. When returning from the script, the gnome-terminal prompt changes the title back to what it was.

Here's the command line for changing the prompt (and the title):

PS1="\[\e]0;NewTitleHere\a\]\u@\h:\w\$ "

and here's the script I use:

#!/bin/bash
xtitle ServerName
ssh user@server.doma.in
Neva
  • 11
  • 1
1

Based on MikeyB's answer above, I created this brief csh script, title to change the title:

#!/bin/csh
echo -n "\e]2;$1\007\e]1;\007"

This can be invoked as: ./title "My New Title"

rambler
  • 11
  • 1
0

Argh, so many answers...

I tried wmctrl, which almost worked, except I couldnt get it to change the icon title, at least not permanently.

The solution is that PS1 in ubuntu sets the title.

The default PS1 is

\[\e]0;\u@\h: \w\a\]${debian_chroot:+($debian_chroot)}\u@\h:\w\$ 

... which sets the title in the first escape sequence.

Thus, there are two solutions:

Solution 1: simplify PS1, then use PROMPT_COMMAND

Change PS1 to something simpler:

PS1="\u@\h:\w\$ "

... then use the PROMPT_COMMAND:

PROMPT_COMMAND='echo -ne "\033]0;SOME TITLE HERE\007"'

Solution 2: directly modify PS1

Simply modify PS1 with new title:

PS1='\[\e]0;newtitle\a\]${debian_chroot:+($debian_chroot)}\u@\h:\w\$ '
Hugh Perkins
  • 1,065
  • 7
  • 9
0

The xterm sequences work fine for gnome-terminal. What shell are you using and what did you put in your shell config file?

wfaulk
  • 6,828
  • 7
  • 45
  • 75
0

To create a new gnome-terminal with a unique specified title, you can specify the title on the command line:

gnome-terminal --title="My New Terminal" &
Randall
  • 606
  • 4
  • 4