Skip to content

Print branch colour depending on name #531

Answered by ericbn
jdiegosierra asked this question in Q&A
Discussion options

You must be logged in to vote

Hola @jdiegosierra. You'll have to test for the branch name value yourself:

zstyle ':zim:git-info:branch' format '%b'
zstyle ':zim:git-info:commit' format '(%c)'

zstyle ':zim:git-info:keys' format \
    'prompt' '$(_prompt_branch_colour)%b%c%f ' \
    'branch' '%b'

_prompt_branch_colour() {
  if [[ ${(e)git_info[branch]} == main ]]; then
    print '%F{red}'
  else
    print '%F{green}'
  fi
}

autoload -Uz add-zsh-hook && add-zsh-hook precmd git-info

PS1='${(e)git_info[prompt]}%# '

Replies: 1 comment 1 reply

Comment options

You must be logged in to vote
1 reply
@jdiegosierra
Comment options

Answer selected by jdiegosierra
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants