Daily Shaarli

All links of one day in a single page.

August 30, 2018

[ZSH] Gathering information from version control systems | User Contributions

In case it might help someone, when developping with VCS.

Copied/pasted from QuickStart:

To get this feature working quickly (including colors), you can do the following (assuming, you loaded vcs_info properly - see above):

zstyle ':vcs_info:' actionformats \
'%F{5}(%f%s%F{5})%F{3}-%F{5}[%F{2}%b%F{3}|%F{1}%a%F{5}]%f '
zstyle ':vcs_info:
' formats \
'%F{5}(%f%s%F{5})%F{3}-%F{5}[%F{2}%b%F{5}]%f '
zstyle ':vcs_info:(sv[nk]|bzr):*' branchformat '%b%F{1}:%F{3}%r'
precmd () { vcs_info }
PS1='%F{5}[%F{2}%n%F{5}] %F{3}%3~ ${vcs_info_msg0}%f%# '

Obviously, the last two lines are there for demonstration. You need to call vcs_info from your precmd function. Once that is done you need a single quoted '${vcs_info_msg0}' in your prompt.

To be able to use '${vcs_info_msg0}' directly in your prompt like this, you will need to have the PROMPT_SUBST option enabled.