【问题标题】:Git branch prompt under Ubuntu not workingUbuntu下的Git分支提示不起作用
【发布时间】:2013-02-15 16:23:20
【问题描述】:

我在 Ubuntu 12.10 下,我已经安装了这个 git-prompt-aware:https://github.com/jimeh/git-aware-prompt

每当我在一个有 git 存储库的目录中时,我需要执行 source ~/.bash_profile 来显示分支。如果我不这样做,它就不会出现。但是,当我关闭终端并转到同一目录时,我需要再次执行 ~/.bash_profile ,有什么想法为什么会发生这种情况?

我的问题是在 .bashrc 中我已经将 PS1 定义为:

case "$TERM" in
    xterm-color) color_prompt=yes;;
esac

# uncomment for a colored prompt, if the terminal has the capability; turned
# off by default to not distract the user: the focus in a terminal window
# should be on the output of commands, not on the prompt
force_color_prompt=yes

if [ -n "$force_color_prompt" ]; then
    if [ -x /usr/bin/tput ] && tput setaf 1 >&/dev/null; then
    # We have color support; assume it's compliant with Ecma-48
    # (ISO/IEC-6429). (Lack of such support is extremely rare, and such
    # a case would tend to support setf rather than setaf.)
    color_prompt=yes
    else
    color_prompt=
    fi
fi

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

这会覆盖我在 .bash_profile 中的内容:

export GITAWAREPROMPT=~/.bash/git-aware-prompt
source $GITAWAREPROMPT/main.sh
export PS1="\u@\h \w\[$txtcyn\]\$git_branch\[$txtylw\]\$git_dirty\[$txtrst\]\$ "

如何将这两种 PS1 设置结合起来?

【问题讨论】:

    标签: git prompt


    【解决方案1】:

    ~/.bash_profile的内容放入~/.bashrc。每次启动终端,都会读取~/.bashrc的内容。

    【讨论】:

      猜你喜欢
      • 2020-05-22
      • 2012-03-31
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多