Skip to content

Instantly share code, notes, and snippets.

@bennyrw
Created October 1, 2020 11:01
Show Gist options
  • Select an option

  • Save bennyrw/76de609d986b3ac6cf6cc204b7f01536 to your computer and use it in GitHub Desktop.

Select an option

Save bennyrw/76de609d986b3ac6cf6cc204b7f01536 to your computer and use it in GitHub Desktop.
Include Git branch in zsh prompt
#
# Prompt customisation for Git branch
#
# Use colors module for simpler usage of colours in prompt
autoload -U colors && colors
# Use vcs_info module for getting Git info (see https://arjanvandergaag.nl/blog/customize-zsh-prompt-with-vcs-info.html)
autoload -Uz vcs_info
# Tell vcs_info to output the current branch, if on a Git repo
zstyle ':vcs_info:git*' formats "%{$fg_bold[cyan]%}(%b)%{$reset_color%}"
# Tell zsh to run vcs_info before every command to update the prompt
precmd() {
vcs_info
}
# Tell zsh to substitute variables in prompt
setopt prompt_subst
# Finally, update the prompt! %{...%} escape non-printable chars, otherwise line wrapping can mess up
# (See http://zsh.sourceforge.net/Doc/Release/Prompt-Expansion.html#Prompt-Expansion)
PROMPT='%{$fg[magenta]%}%n@%m%{$reset_color%} %{$fg[white]%}%1~%{$reset_color%} ${vcs_info_msg_0_} %# '
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment