I've tried setting my PROMPT_COMMAND variable:
PROMPT_COMMAND='echo -ne "\033]0;"myWindowTitle"\007"'
but something changes my tab (or the whole terminal title) to 'user@hostname:/current/path', thus
PROMPT_COMMAND='echo -ne "\033]0;"myWindowTitle"\007" && sleep 3'
changes title for 3 second only :)
The Bash escape sequence to set the terminal title looks like this: \[\e]2;new title\a\] , and to apply this title to your terminal window, all you have to do is modify its "Prompt String 1", or PS1 variable, by adding this "set title" escape sequence after your current Prompt String 1, like this: PS1="${PS1}\[\e]2;new ...
GNOME Terminal ( gnome-terminal from the command line or GNOME's Alt-F2 launcher) emulates the xterm terminal emulator and provides some of the same features.
Naming Your Terminal tabs Given that we might be using a number of terminal sessions with a number of different processes or parameters, it's useful to rename the tabs to something helpful. You can do this from the context menu, which you can open by right-clicking on the tab.
PROMPT_COMMAND
is issued before a prompt is set based on the PS1
variable. Probably you have some character sequence in PS1 which sets your windows title. You may invoke unset PS1
or set it to some other value:
export PS1='${debian_chroot:+($debian_chroot)}\u@\h:\w\$ '
Alternatively you can set window title in your PS1 variable:
export PS1='\[\e]0;myWindowTitle\a\]${debian_chroot:+($debian_chroot)}\u@\h:\w\$'
In Ubuntu the .bashrc file has some code that adds text to the PS1 variable. This extra text changes the title after you set it with the --title option. Just comment it.
# 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
Rather than do:
PS1='\[\e]0;myWindowTitle\a\]${debian_chroot:+($debian_chroot)}\u@\h:\w\$'
Try using a variable and setting this in your .bashrc:
PS1='\[\e]0;$WT\a\]${debian_chroot:+($debian_chroot)}\u@\h:\w\$'
Then you can simply do this to change the window title at the prompt by:
WT="my new window title"
If you like, you can include the path in the window title in your .bashrc:
PS1='\[\e]0;$WT: \w\a\]${debian_chroot:+($debian_chroot)}\u@\h:\w\$'
BTW, I don't think you need to "export" PS1.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With