Как изменить цвет ветки git, отображаемой в bash [дубликат]

Я использую это руководство , чтобы отображать имя ветки в терминале gnome (Ubuntu 15.10) при работе в репозитории git. На основании вышеизложенного у меня теперь есть следующее в моем файле ~ / .bashrc :

# 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 

...

# Add git branch if its present to PS1
parse_git_branch() {
 git branch 2> /dev/null | sed -e '/^[^*]/d' -e 's/* \(.*\)/(\1)/'
}
if [ "$color_prompt" = yes ]; then
 PS1='${debian_chroot:+($debian_chroot)}\[\033[01;32m\]\u@\h\[\033[00m\]:\[\033[01;34m\]\w\[\033[01;31m\]$(parse_git_branch)\[\033[00m\]\$ '
else
 PS1='${debian_chroot:+($debian_chroot)}\u@\h:\w$(parse_git_branch)\$ '
fi
unset color_prompt force_color_prompt

В результате я теперь получаю:

enter image description here

так что он работает . Но почему была удалена окраска моего user @ host? И я также ожидал, что имя ветки должно быть окрашено. Раньше это выглядело так:

enter image description here

ОБНОВЛЕНИЕ: Вместо этого я попробовал это руководство:

https://coderwall.com/p/fasnya/add-git-branch -name-to-bash-prompt

добавление этого в .bashrc:

parse_git_branch() {
     git branch 2> /dev/null | sed -e '/^[^*]/d' -e 's/* \(.*\)/ (\1)/'
}
export PS1="\u@\h \[\033[32m\]\w\[\033[33m\]\$(parse_git_branch)\[\033[00m\] $ "

и это работает:

enter image description here

Обратите внимание, что в .bashrc у меня также есть это (по умолчанию):

# 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

Мне еще предстоит найти причину, почему этот фрагмент дает правильное ct результат, а другая версия - нет. Есть какие-нибудь комментарии по этому поводу?

Вот версия моего .bashrc, в которой включен старый фрагмент, который не работает:

http://pastebin.com/M8kjEiH3

166
задан 7 February 2016 в 11:39

0 ответов

Другие вопросы по тегам:

Похожие вопросы: