我试过设置我的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 秒 :)
我试过设置我的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 秒 :)
PROMPT_COMMAND
在基于PS1
变量设置提示之前发出。可能你在 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
标题将立即更改:-)