Use the -t
option. (see gnome-terminal --help-terminal-options
)
gnome-terminal \
--tab -t "notes" --working-directory=$HOME/notes \
--tab -t "puppet" --working-directory=$HOME/puppet \
--tab -t "beamish" --profile=root-beamish \
--tab -t "odyssey" --profile=odyssey \
--tab -t "root" --profile=root
-------- updated at 2011-11-15 22:00:00 --------
So... that worked for me on Solaris 11 Express, with gnome-terminal 2.30.2.
Since then, I've been able to test it on Ubuntu 11.04 (Natty), which uses 2.32.1, and found exactly the same behavior as you.
In the case of Ubuntu, I was able to track it to the ubuntu .bashrc
file. In particular, the section that looks like:
# If this is an xterm set the title to user@host:dir
case "$TERM" in
xterm*|rxvt*)
PS1="\[\e]0;${debian_chroot:+($debian_chroot)}\u@\h: \w\a\]$PS1"
;;
*)
;;
esac
In this case, the PS1 variable is being expanded for terminal types matching xterm*
and rxvt*
.
PS1="\[\e]0;${debian_chroot:+($debian_chroot)}\u@\h: \w\a\]$PS1"
specifically the part between PS1="\[\e]0;
and \a\]
. Those get turned into the window title.
Once I commented out that whole case
statement, the behavior of gnome-terminal with the -t
option worked as expected. I'll see if I can find a CentOS 6 box to test this with, too.
-------- updated at 2017-11-1 09:38:00 --------
So it looks like more recent versions of Gnome-Terminal have made away with some useful features, like the simple -t
option to set terminal titles.
It is still possible to set terminal titles at runtime, it's just ugly as hell now. You can use printf
or echo
in the command to effect a title.
For example:
To start a terminal window with 1 tab, titled 'My Fancy Title' using printf
:
gnome-terminal --tab -e 'bash -c "printf \"\e]2;My Fancy Title\a\"; bash -i"'
To start a terminal window with 2 tabs, one running top, and one with a title, using echo
:
gnome-terminal \
--tab -e 'bash -c "echo -ne \"\033]0;my tab running top\007\"; top"' \
--tab -e 'bash -c "echo -ne \"\033]0;My Fancy Title\007\"; bash -i"'
This does at least offer an option for setting the terminal title at runtime.
See this post for an option to put a simple function in your ~/.bashrc
to allow for setting and resetting the title at will.
The script works by setting the shell's interactive prompt to a string which includes control codes to manipulate the xterm
window title. Each time the shell's prompt is displayed, the control codes to change the window title are output.
But of course, inside a script, no interactive prompt is ever displayed, so these commands have no observable effect (though if you started another interactive shell from within the script, you could see the window title change). And because no script can change the environment of its parent process, the change is lost once your script terminates.
Anyway, from your script, you could of course print out the control codes directly.
printf '\033]2;Hello\a'
This changes the window's title once, but if any other program later changes it again, your old title will be lost. The trick to change your prompt is widespread because some popular programs in the past would often change your window title soon after you changed it to your liking (though I don't think this is a common problem any longer). The drawback is that if something has a genuine reason to change your window title, that will now be superseded as soon as your shell displays its prompt again.
If you want code to change your current shell's prompt, you can't put those in a regular script; but you can source
the script file, or put the commands in a shell function instead (commonly done in your Bash profile in order to make it persistent).
Incidentally, the Bash prompt should include additional control codes to tell Bash when a part of the prompt is effectively zero width, as far as calculating the display width of the prompt is concerned. You will find that line wrapping is erratic if you type a long command and then need to backspace, for example; Bash will attempt to redraw the prompt, but does it in the wrong place, because it thinks the screen control codes contribute to the prompt's width. You'll want to add these \[
and \]
Bash control codes around them.
PS1="$ORIG\[$TITLE\]"
(The curly braces aren't really contributing anything, and hamper legibility, so I took them out.)
Best Answer
Instant of using function
set-title
you can create command with this functionality, so remove functionset-title()
that you add from~/.bashrc
and create a file/usr/local/bin/set-title
:Add chmod:
chmod +x /usr/local/bin/set-title
. And after you re-open terminal you can use this command by:set-title TEST
(If you have/usr/local/bin/
in your$PATH
).And then you can use it when creating new tab by this way:
If you somehow don't have
/usr/local/bin/
in your$PATH
, you can try with absolute path to the set-title command: