繁体   English   中英

如何在 Ubuntu 10 中更改 gnome-terminal 标题

[英]How to change gnome-terminal title in Ubuntu 10

我试过设置我的PROMPT_COMMAND变量:

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

但是有些东西将我的选项卡(或整个终端标题)更改为“ user@hostname:/current/path ”,因此

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

仅更改标题 3 秒 :)

在基于PS1变量设置提示之前发出PROMPT_COMMAND 可能你在 PS1 中有一些字符序列来设置你的窗口标题。 您可以调用unset PS1或将其设置为其他值:

export PS1='${debian_chroot:+($debian_chroot)}\u@\h:\w\$ '

或者,您可以在 PS1 变量中设置窗口标题:

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\$'

然后,您可以简单地通过以下方式在提示符处更改窗口标题:

WT="my new window title"

如果您愿意,可以在 .bashrc 的窗口标题中包含路径:

PS1='\[\e]0;$WT: \w\a\]${debian_chroot:+($debian_chroot)}\u@\h:\w\$'

顺便说一句,我认为您不需要“导出” PS1。

获取 justingordon的答案并运行它,找到在 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 ,标题将立即更改 :-)

在 Ubuntu 中,通过添加以下行添加一个函数来设置.bashrc上的标题:

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'
}

然后只需使用:

settitle FooBar 

将标题设置为例如FooBar 在此处输入图像描述 如果您有多个选项卡,这将设置当前选项卡的标题。 窗口的标题始终是当前选定选项卡的标题。 在此处输入图像描述

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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