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

ZSH git prompt not detecting git changes #55

Open
cevaris opened this issue Mar 5, 2015 · 8 comments
Open

ZSH git prompt not detecting git changes #55

cevaris opened this issue Mar 5, 2015 · 8 comments

Comments

@cevaris
Copy link

cevaris commented Mar 5, 2015

Also, seems that __CURRENT_GIT_STATUS is not auto updating as well.

To reporoduce

  • I start with a clean git state of master branch.
  • Touch a new file blah
  • See that the git status prompt did not update
  • Re-source my ~/.zshrc file and it picks up the new untracked file
dots (master|✔) ~࿔ git st
On branch master
Your branch is up-to-date with 'origin/master'.
nothing to commit, working directory clean
dots (master|✔) ~࿔ touch blah
dots (master|✔) ~࿔ git st
On branch master
Your branch is up-to-date with 'origin/master'.
Untracked files:
  (use "git add <file>..." to include in what will be committed)

        blah

nothing added to commit but untracked files present (use "git add" to track)
dots (master|✔) ~࿔ source ~/.zshrc
dots (master|?) ~࿔
@cevaris
Copy link
Author

cevaris commented Mar 5, 2015

Fixed by defining a precmd function in my .zshrc file.

source ~/.zsh.d/zsh-git-prompt/zshrc.sh
function precmd {
    PROMPT="%{$fg[green]%}%c $(git_super_status)%{$fg[red]%}~%{$fg[white]%}࿔ %{$reset_color%}"
}

@klaasb
Copy link

klaasb commented Mar 5, 2015

You can also fix it by using single quotes, so the variables and commands in PROMPT don't get evaluated when sourcing .zshrc. See here: http://unix.stackexchange.com/questions/14266/how-do-you-make-rprompt-in-zsh-update-itself-on-every-enter

@zhimsel
Copy link

zhimsel commented Mar 5, 2015

@cevaris That actually seems to have worked. I'll test the rest of today and see if there are any bugs or situations where it doesn't work. Thanks!

zhimsel added a commit to zhimsel/dotfiles that referenced this issue Mar 5, 2015
@cevaris
Copy link
Author

cevaris commented Mar 6, 2015

👍

@yibum
Copy link

yibum commented Feb 15, 2016

@klaasb Changing to single quotes works for me. Thanks!

@therealplato
Copy link

+1 for single quote fix
I used it to implement a much simpler color indicator
screen shot 2016-04-26 at 9 48 05 am

p1xelHer0 added a commit to p1xelHer0/dotfiles that referenced this issue Apr 13, 2017
this is because using single quotes in a variable assignment delays evaluation, therefore we will update the git status at every update, not only at the sourcing time of the .zshrc! (Kinda, something like that, see: olivierverdier/zsh-git-prompt#55)
@aamnah
Copy link

aamnah commented May 3, 2020

Just a note that this single quote thing is valid for all files in the custom/ folder.

This gave me a hard time after having copied over code from my .bash_aliases. Some aliases there defined with double quotes made my git prompt stopped working again.

The following will cause issues

## Recursively delete `.DS_Store` files
alias cleanup="find . -type f -name '*.DS_Store' -ls -delete"

## Kill all the tabs in Chrome to free up memory
# [C] explained: http://www.commandlinefu.com/commands/view/402/exclude-grep-from-your-grepped-output-of-ps-alias-included-in-description
alias chromekill="ps ux | grep '[C]hrome Helper --type=renderer' | grep -v extension-process | tr -s ' ' | cut -d ' ' -f2 | xargs kill"

Had to flip the single and double arrangement: single quote outside, double quote inside

## Recursively delete `.DS_Store` files
alias cleanup='find . -type f -name "*.DS_Store" -ls -delet'

## Kill all the tabs in Chrome to free up memory
# [C] explained: http://www.commandlinefu.com/commands/view/402/exclude-grep-from-your-grepped-output-of-ps-alias-included-in-description
alias chromekill='ps ux | grep "[C]hrome Helper --type=renderer" | grep -v extension-process | tr -s " " | cut -d " " -f2 | xargs kill'

@sisrfeng
Copy link

source ~/dotF/zsh-git-prompt/zshrc.sh


function precmd {
export RPS1='$(git_super_status)'
}

inodb added a commit to inodb/dotfiles that referenced this issue Jan 30, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

7 participants