Automatically change the gnome-terminal “title” for the window

gnome

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

Best Answer

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'