简体   繁体   中英

How to change gnome-terminal title in Ubuntu 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 :)

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.

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

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 eg FooBar : 在此处输入图像描述 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. 在此处输入图像描述

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM