如何在Ubuntu 10中更改gnome终端标题

如何在Ubuntu 10中更改gnome终端标题,ubuntu,tabs,title,gnome-terminal,Ubuntu,Tabs,Title,Gnome Terminal,我已尝试设置我的提示符命令变量: PROMPT_COMMAND='echo -ne "\033]0;"myWindowTitle"\007"' export PS1='\[\e]0;myWindowTitle\a\]${debian_chroot:+($debian_chroot)}\u@\h:\w\$' 但是我的标签(或整个终端标题)被更改为“user@hostname:/current/path,因此 PROMPT_COMMAND='echo -ne "\033]0;"myWindowT

我已尝试设置我的提示符命令变量:

PROMPT_COMMAND='echo -ne "\033]0;"myWindowTitle"\007"'
export PS1='\[\e]0;myWindowTitle\a\]${debian_chroot:+($debian_chroot)}\u@\h:\w\$'
但是我的标签(或整个终端标题)被更改为“user@hostname:/current/path,因此

PROMPT_COMMAND='echo -ne "\033]0;"myWindowTitle"\007" && sleep 3'

仅更改标题3秒钟:)

PROMPT\u命令在基于
PS1
变量设置提示之前发出。可能PS1中有一些字符序列,用于设置windows标题。您可以调用
取消设置PS1
或将其设置为其他值:

export PS1='${debian_chroot:+($debian_chroot)}\u@\h:\w\$ '
或者,您可以在PS1变量中设置窗口标题:

PROMPT_COMMAND='echo -ne "\033]0;"myWindowTitle"\007"'
export PS1='\[\e]0;myWindowTitle\a\]${debian_chroot:+($debian_chroot)}\u@\h:\w\$'

在Ubuntu中.bashrc文件有一些代码,可以将文本添加到PS1变量中。使用--title选项设置标题后,此额外文本将更改标题。评论一下吧

# 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
而不是:

PS1='\[\e]0;myWindowTitle\a\]${debian_chroot:+($debian_chroot)}\u@\h:\w\$'
尝试使用一个变量并在.bashrc中设置:

PS1='\[\e]0;$WT\a\]${debian_chroot:+($debian_chroot)}\u@\h:\w\$'
PS1='\[\e]0;$WT: \w\a\]${debian_chroot:+($debian_chroot)}\u@\h:\w\$'
然后,您只需执行以下操作即可在提示下更改窗口标题:

WT="my new window title"
如果愿意,可以在.bashrc中的窗口标题中包含路径:

PS1='\[\e]0;$WT\a\]${debian_chroot:+($debian_chroot)}\u@\h:\w\$'
PS1='\[\e]0;$WT: \w\a\]${debian_chroot:+($debian_chroot)}\u@\h:\w\$'
顺便说一句,我认为您不需要“导出”PS1。

获取的答案,然后运行它,在bashrc中找到第二个出现的PS1集,如下所示:

# 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"
改为:

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"

现在,标题将以变量
title
作为前缀。只需更改终端中
TITLE
的值,例如
TITLE=ec2
,标题将立即更改:-)

细微差别,如果您在
\
前面放置一个
\
,则可以更改WT变量“in live”,它将立即更改终端标题:-)