【问题标题】:How the PS1 of the title doesn't overwrite the PS1 of the prompt标题的 PS1 如何不覆盖提示的 PS1
【发布时间】:2020-12-18 07:24:12
【问题描述】:

我注意到~/.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 并决定title

但是它们都改变了 same 环境变量,所以当终端启动并“看到”PS1 设置为 提示文本 时,如何它也可以设置标题? ~/.bashrc 是否被加载了两次?

【问题讨论】:

    标签: bash terminal ps1


    【解决方案1】:

    第一个条件根据$color_prompt是否启用设置$PS1。第二个分配通过将$PS1 设置为一个表达式来扩展它包含$PS1 的先前值

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

    【讨论】:

    • 哦,我明白了,我错过了。谢谢你
    猜你喜欢
    • 2019-08-30
    • 2016-03-18
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2022-01-20
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多