在 Windows 上的 Ubuntu 上更改 Bash 的标题

Mat*_*ita 5 windows bash ubuntu windows-10 windows-subsystem-for-linux

是否可以更改 Windows 上 Ubuntu 上的 Bash 在其标题栏中显示的标题?默认情况下,它设置为<username>@<computername>:<CWD>. 我想说,Bash on Ubuntu on Windows:作为前缀添加到它。

我尝试了一些向.bashrc(例如使用xtitle)添加不同行的解决方案,但问题是 BoUoW 每次更改 CWD 时都会更改其标题,因此它会立即覆盖您在.bashrc.

有没有办法永久添加前缀或完全更改磁贴?

小智 3

如果您使用 WSL,您可以~/.bashrc在发行版中编辑文件。这也适用于Windows 终端(至少在 0.7 版本中)。

您需要\[\e]0;按照此处的说明进行查找: https: //askubuntu.com/a/405769/808082

Ubuntu 18.4.bashrc的示例:

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

这意味着标题设置为${debian_chroot:+($debian_chroot)}\u@\h: \w\a\

根据您的情况,您需要将其更改为:

PS1="\[\e]0;Bash on Ubuntu on Windows: ${debian_chroot:+($debian_chroot)}\u@\h: \w\a\]$PS1"
Run Code Online (Sandbox Code Playgroud)