标题的PS1如何不覆盖提示的PS1

E235

我注意到其中~/.bashrc有两组PS1

if [ "$color_prompt" = yes ]; then
    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*)
    PS1="\[\e]0;${debian_chroot:+($debian_chroot)}\u@\h:\w\a\]$PS1"
    ;;
*)
    ;;
esac

第一个检查是否为$color_prompt真,并确定提示文本
第二个检查$TERM并确定标题

但是它们两个都更改了相同的环境变量,因此,当终端启动并“看到”PS1提示文本设置的内容时,它又如何设置标题?~/.bashrc加载两次?

穆雷尼克

第一个条件$PS1根据是否$color_prompt启用进行设置第二个分配的扩展了此方法,方法是将设置$PS1为,其中包含的先前值$PS1

PS1="\[\e]0;${debian_chroot:+($debian_chroot)}\u@\h:\w\a\]$PS1"
# Here ---------------------------------------------------^

本文收集自互联网,转载请注明来源。

如有侵权,请联系[email protected] 删除。

编辑于
0

我来说两句

0条评论
登录后参与评论

相关文章