我希望我的窗口标题栏显示我的 PWD。在我的文件中.bashrc,我有这个似乎对 Bash 有用:
# 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
Run Code Online (Sandbox Code Playgroud)
但是,当我使用 Tmux 时,窗口显示我启动 Tmux 的目录,而不是我在 Tmux 中导航到的当前目录。
下面,我在 中启动了 Tmux ~,然后导航到~/Downloads。标题栏仍然显示~。它后面是一个窗口,我~/Downloads仅使用 Bash 即可导航到该窗口;它显示了我想要的:

以下是我已经尝试过但不起作用的事情:
我想当我尝试这个之前它与其他一些更改相结合......现在它可以工作:
在~/.tmux.conf:
set -g set-titles on
set -g set-titles-string '#T'
Run Code Online (Sandbox Code Playgroud)
在~/.bashrc(顺便说一句,我添加|screen到 switch 语句中):
if [ "$color_prompt" = yes ]; then
PS1='> '
#PS1='${debian_chroot:+($debian_chroot)}\[\033[01;32m\]\u@\h\[\033[00m\]:\[\033[01;34m\]\w\[\033[00m\]\$ '
else
PS1='${debian_chroot:+($debian_chroot)}\u@\h:\w\$ '
fi
unset color_prompt force_color_prompt
# If this is an xterm set the title to user@host:dir
case "$TERM" in
xterm*|rxvt*|screen)
PS1="\[\e]0;${debian_chroot:+($debian_chroot)}\u@\h: \w\a\]$PS1"
;;
*)
;;
esac
Run Code Online (Sandbox Code Playgroud)