0

我在 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 设置?

4

1 回答 1

1

把里面的内容放进~/.bash_profile~/.bashrc。每次启动终端时,~/.bashrc都会读取 的内容。

于 2013-02-15T16:24:38.187 回答