How to add git vcs_info to the prompt_bart_setup theme in zsh?

I’m trying to modify the bart theme so it includes git status information. I got it to work, but it doesn’t update when I change directories

I modified the bart theme by enabling vcs_info:

  • Move last n commits from svn to git repo
  • Using xxdiff to merge in linux?
  • jGit clone remote git respository from Java
  • Git wont let rebase despite no diff
  • Notation anomaly of symmetric/asymmetric between rev-list and diff
  • Is there any git management GUI?
  • prompt_bart_setup () {
        # ...
        autoload -Uz vcs_info
        # Set vcs_info parameters.
        zstyle ':vcs_info:*' enable bzr git hg svn
        zstyle ':vcs_info:*' check-for-changes true
        zstyle ':vcs_info:*' stagedstr '%F{green}●%f'
        zstyle ':vcs_info:*' unstagedstr '%F{yellow}●%f'
        zstyle ':vcs_info:*' formats ' - [%b%c%u]'
        zstyle ':vcs_info:*' actionformats " - [%b%c%u|%F{cyan}%a%f]"
        zstyle ':vcs_info:(sv[nk]|bzr):*' branchformat '%b|%F{cyan}%r%f'
        zstyle ':vcs_info:git*+set-message:*' hooks git-status
        # ...
    prompt_bart_precmd () {
        # ...
        # ...

    And populating the RPROMT variable (it also works with PS1, but I wanted to isolate the problem):

    prompt_bart_ps1 () {
        # ...
        # ...

    This works if I create a new terminal session in a git repo, but it doesn’t update when I change directories.

    I’ve seen suggestions to use single quotes, but when I change it to this:

    prompt_bart_ps1 () {
        # ...
        setopt promptsubst
        # ...

    The prompt shows literally ${vcs_info_msg_0_}. Any ideas?

  • How can I make GIT to default to my home folder?
  • How do I fork an empty repository on github?
  • Git show doesn't work
  • How do I run git bisect only on commits that changed a certain file?
  • Rebase against the main branch
  • git-http-backend and ldap authentication, push error: requested URL returned error: 401 Authorization Required
  • One Solution collect form web for “How to add git vcs_info to the prompt_bart_setup theme in zsh?”

    There seems to be a problem with promptsubst. RPROMPT="${vcs_info_msg_0_}" will substitute the value of vcs_info_msg_0_ when RPROMPT is first defined. That is the reason why it works when you open a shell in a repository but not when you change into one.

    The single-quoted variant prevents this initial substitution and setopt promptsubst should then do the substitution everytime the prompt is used. But in your case it doesn’t, obviously. Possibly, there is a setopt nopromptsubst somewhere in your zsh configuration that gets called after the one in prompt_bart_setup.

    See with setopt | grep promptsubst if it is really set.

    Git Baby is a git and github fan, let's start git clone.