How to change gnome-terminal title in Ubuntu 10
Asked Answered
P

5

10

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 :)

Perl answered 14/10, 2010 at 10:9 Comment(0)
G
8

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\$'
Griceldagrid answered 15/10, 2010 at 9:2 Comment(0)
A
2

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
Aurelie answered 12/7, 2011 at 18:18 Comment(0)
L
2

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.

Lucy answered 27/11, 2011 at 3:46 Comment(1)
slight nuance, if you put a \ in front of $WT, then you can change the WT variable 'in live', and it will immediately change your terminal title :-)Gillenwater
G
0

Taking justingordon's answer, and running with it, find the second occurrence of PS1 set in bashrc, which looks like this:

# If this is an xterm set the title to user@host:dir
case "$TERM" in
xterm*|rxvt*)
    PS1="\[\e]0;\${TITLE} ${debian_chroot:+($debian_chroot)}\u@\h: \w\a\]$PS1"

change to:

export TITLE=bash
# If this is an xterm set the title to user@host:dir
case "$TERM" in
xterm*|rxvt*)
    PS1="\[\e]0;\${TITLE} ${debian_chroot:+($debian_chroot)}\u@\h: \w\a\]$PS1"

Now, the title will be prefixed with the variable TITLE. Just change the value of TITLE in your terminal, eg TITLE=ec2 and the title will immediately change :-)

Gillenwater answered 21/1, 2016 at 12:36 Comment(0)
F
0

In Ubuntu add a function to set the title on your .bashrc by adding the lines:

settitle () {
  export PS1='${debian_chroot:+($debian_chroot)}\[\033[01;32m\]\u@\h\[\033[00m\]:\[\033[01;34m\]\w\[\033[00m\]\$ '
  echo -ne '\033]0;'"$1"'\a'
}

Then simply use:

settitle FooBar 

to set the title to e.g. FooBar: enter image description here If you have multiple tabs, this will set the title of the current tab. The title of the window is at all times that of the currently selected tab. enter image description here

Fergus answered 4/7, 2022 at 12:55 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.