Take the 2-minute tour ×
Server Fault is a question and answer site for professional system and network administrators. It's 100% free, no registration required.

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

share|improve this question
add comment

7 Answers

To change the title of the current window :

wmctrl -r :ACTIVE: -N "MyWindowTitle"

share|improve this answer
add comment

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'
share|improve this answer
add comment

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

share|improve this answer
add comment

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"

share|improve this answer
add comment

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

share|improve this answer
add comment

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" &
share|improve this answer
add comment

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\$ '
share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.