Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

mac os zsh git-prompt.sh cannot get colors to work

Tags:

git

I copied git-prompt.sh (https://github.com/git/git/blob/master/contrib/completion/git-prompt.sh) to ~/.git-prompt.sh

Then in my .zsrhc I have

source ~/.git-prompt.sh
setopt PROMPT_SUBST ; PS1='[%n@%m %c$(__git_ps1 " (%s)")]\$ '

The branch shows but it doesn't show color.

like image 735
Chris Muench Avatar asked Sep 20 '25 00:09

Chris Muench


1 Answers

Coloring is enabled in line 557:

# NO color option unless in PROMPT_COMMAND mode
if [ $pcmode = yes ] && [ -n "${GIT_PS1_SHOWCOLORHINTS-}" ]; then
    __git_ps1_colorize_gitstring
fi

You can either get rid of the whole if condition and just leave __git_ps1_colorize_gitstring or enable precmd which is ZSH equivalent for PROMPT_COMMAND and what pcmode stands for here and enable GIT_PS1_SHOWCOLORHINTS:

$ source ~/.git-prompt.sh
$ GIT_PS1_SHOWCOLORHINTS=true
$ precmd () { __git_ps1 "%n" ":%~$ " "|%s" }
like image 134
Arkadiusz Drabczyk Avatar answered Sep 22 '25 15:09

Arkadiusz Drabczyk