像 Terminator 或 Guake 终端这样的终端无法解析 .bashrc 文件中设置的 git 提示配置文件

像 Terminator 或 Guake 终端这样的终端无法解析 .bashrc 文件中设置的 git 提示配置文件

像 Terminator 或 Guake 终端这样的终端无法解析 .bashrc 文件中设置的 git 提示配置文件。对于使用 xterm 作为 guake 和 terminator 终端使用的基础的终端,未设置 PS1 变量。因此,如果使用自定义函数来显示自定义路径(如果当前目录是 GIT 目录),那么这些变量或函数将不起作用。

例如:$parse_git_branch

答案1

设置 PS1 之前设置PS1后

我找到了解决方案,它是在我的主目录中使用 .bashrc 文件。如果我们在文本编辑器中打开这个文件,我们会在这里找到一行,它检查当前终端是否是 xterm 并为其设置一些值:

# 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,然后简单地将 PS1 替换为以下值:

    parse_git_branch() {
  git branch 2> /dev/null | sed -e '/^[^*]/d' -e 's/* \(.*\)/(\1)/'
}

# If this is an xterm set the title to user@host:dir
# old value:PS1="\[\e]0;${debian_chroot:+($debian_chroot)}\u@\h: \w\a\]$PS1"

case "$TERM" in
xterm*|rxvt*)
    PS1="${debian_chroot:+($debian_chroot)}\[\033[1;34m\]\H:\[\033[1;35m\]\[\033[1;35m\]\w\[\033[1;92m\]\$(parse_git_branch)\[\033[0m\]$ "
    ;;
*)
    ;;
esac

相关内容