Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Git status not refreshing #4826

Closed
alecho opened this issue Feb 4, 2016 · 3 comments

Comments

@alecho
Copy link

commented Feb 4, 2016

When using my custom theme. Git information like branch, remote status, etc doesn't refresh on git checkout for example.

My custom theme:

# vim:ft=zsh ts=2 sw=2 sts=2

rvm_current() {
  rvm current 2>/dev/null
}

rbenv_version() {
  rbenv version 2>/dev/null | awk '{print $1}'
}

if [ -e ~/.rvm/bin/rvm-prompt ]; then
  RPROMPT='%{$fg_bold[red]%}‹$(rvm_current)›%{$reset_color%}'
else
  if which rbenv &> /dev/null; then
    RPROMPT='%{$fg_bold[red]%}$(rbenv_version)%{$reset_color%}'
  fi
fi

git_commits_behind() {
  if $(echo "$(command git status -sb 2> /dev/null)" | grep 'behind' &> /dev/null); then
    local COMMITS
    COMMITS=$(command git status -sb 2> /dev/null | sed -e 's/^.*behind \([0-9]*\).*/\1/')
    echo "$ZSH_THEME_GIT_COMMITS_BEHING_PREFIX$COMMITS$ZSH_THEME_GIT_COMMITS_BEHIND_SUFFIX"
  fi
}

# Must use Powerline font, for \uE0A0 to render.
ZSH_THEME_GIT_PROMPT_PREFIX=" %{$fg[magenta]%}\uE0A0 "
ZSH_THEME_GIT_PROMPT_SUFFIX="%{$reset_color%}"
ZSH_THEME_GIT_PROMPT_DIRTY="%{$fg[red]%}!"
ZSH_THEME_GIT_PROMPT_UNTRACKED="%{$fg[green]%}?"
ZSH_THEME_GIT_PROMPT_CLEAN=""
ZSH_THEME_GIT_PROMPT_AHEAD_REMOTE="%{$fg[green]%}+$(git_commits_ahead)"
ZSH_THEME_GIT_PROMPT_BEHIND_REMOTE="%{$fg[red]%}-$(git_commits_behind)"
ZSH_THEME_GIT_PROMPT_DIVERGED_REMOTE="%{$fg[green]%}+$(git_commits_ahead) %{$fg[red]%}-$(git_commits_behind)"
ZSH_THEME_GIT_PROMPT_REMOTE_EXISTS=" %{$fg[green]%}\u2713"
ZSH_THEME_GIT_PROMPT_REMOTE_MISSING="\u2717"

PROMPT='
%{$fg_bold[green]%}${PWD/#$HOME/~}%{$reset_color%}
$ '

RPROMPT="%{$(echotc UP 1)%}$(git_prompt_info)$(git_prompt_remote) $(git_remote_status)%{$reset_color%}%{$(echotc DO 1)%}"

@apjanke

This comment has been minimized.

Copy link
Contributor

commented Feb 4, 2016

Looks like you should be using single quotes instead of double quotes for the strings containing $(git...) invocations, so they're evaluated each time the prompt is displayed, instead of once at prompt definition time.

@mcornella

This comment has been minimized.

Copy link
Collaborator

commented Feb 4, 2016

That's exactly it. To clarify, @apjanke refers to your RPROMPT variable:

RPROMPT="$(command)"  # this will run command, then set RPROMPT to the result
RPROMPT='$(command)'  # this will set RPROMPT to run command each time it is printed
@mcornella mcornella closed this Feb 4, 2016
@alecho

This comment has been minimized.

Copy link
Author

commented Feb 4, 2016

Thank you so much!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
3 participants
You can’t perform that action at this time.