Search code examples
formatzshprompt

Removing VCS from vcs_info prompt in zsh name to use ZSH_THEME_GIT_PROMPT_DIRTY


I currently have this set up in my .zshrc

autoload -Uz add-zsh-hook vcs_info
setopt prompt_subst
add-zsh-hook precmd vcs_info
add-zsh-hook precmd my_precmd

zstyle ':vcs_info:git:*' formats '%b%u%c'

and in my precmd function I set my RPROMPT to be $(git_prompt_info). I also colour it based on the name of the branch (ie main might be blue, while WIP is red etc).

The issue I have is that it always prints out with a git prefix (like this git:(main)).

I checked the docs and it shows that from :vcs_info:vcs-string:user-context:repo-root-namethe relevant part I want to get rid of is vcs-string but I can't find a way to remove it.

I know I can just use ${vcs_info_msg_0_} but I'm trying to incorporate ZSH_THEME_GIT_PROMPT_CLEAN and ZSH_THEME_GIT_PROMPT_DIRTY and haven't found a way to do so with vcs_info

Any help would be appreciated.


Solution

  • Turns out to get access to the ZSH_THEME_GIT_PROMPT_CLEAN and ZSH_THEME_GIT_PROMPT_DIRTY parts of the prompt, you can just call directly into the zsh code

    So now my prompt colouring is basically

      if [[  "${vcs_info_msg_0_}" != "" ]]
        then
          [[ "${vcs_info_msg_0_}" == "master" || "${vcs_info_msg_0_}" == "main" ]] && git2color='196'
          local git2="%B%F{${git2color}}(${vcs_info_msg_0_}$(parse_git_dirty))%f%b "
      fi