Pure: Git info not showing up next to directory

Created on 23 Sep 2018  Â·  15Comments  Â·  Source: sindresorhus/pure

General information

  • Pure version: 1.8.0
  • ZSH version: 5.3.0
  • Terminal program & version: 2.0.0
  • Operating system: macOS Sierra 10.13.6
  • ZSH framework: oh-my-zsh

I have:

  • [X] Followed the Integration instructions for my framework
  • [X] Tested with another terminal program and can reproduce the issue:

Problem description

When inside of a git repo, I do not see the current branch name or the * when files are changed.

Reproduction steps

  1. open Hyper
  2. cd into any git repo

My .zshrc:

# Path to your oh-my-zsh installation.
export ZSH=/Users/mattgabor/.oh-my-zsh

ZSH_THEME=""

plugins=(git web-search statify zsh-autosuggestions zsh-syntax-highlighting)

export GOPATH=$HOME/golang
export PATH=$PATH:$GOPATH/bin

export PATH="/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin"

source $ZSH/oh-my-zsh.sh

source ~/.profile
source ~/.aliases

export PATH="/usr/local/sbin:/usr/local/share/npm/bin:$PATH"

export NVM_DIR="/Users/mattgabor/.nvm"
[ -s "$NVM_DIR/nvm.sh" ] && . "$NVM_DIR/nvm.sh"  # This loads nvm

export PATH="/usr/local/mysql/bin:$PATH" # Add MYSQL to PATH
[ -s "$NVM_DIR/bash_completion" ] && \. "$NVM_DIR/bash_completion"  # This loads nvm bash_completion

# Add RVM to PATH for scripting. Make sure this is the last PATH variable change.
export PATH="$PATH:$HOME/.rvm/bin"
[[ -s "$HOME/.avn/bin/avn.sh" ]] && source "$HOME/.avn/bin/avn.sh" # load avn

# enable pure theme
autoload -U promptinit; promptinit
prompt pure

All 15 comments

image

Do you use any type of authentication with Git? Password prompt, pinentry, or similar?

Can you also test the master branch of Pure to see if it is affected as well?

I started to have the same issue but randomly, sometimes I do get the git info and others it just goes away like in the posted image, I have a slightly modified prompt_pure_preprompt_render() to get more details, the ones I just move across updates but just now is when I started to notice this strange behavior, this are my changes applied to the lates pure release, (working, but randomly going away)

https://github.com/sindresorhus/pure/blob/master/pure.zsh#L120-L124 with:

# Add git branch and dirty status info.
     typeset -gA prompt_pure_vcs_info
     if [[ -n $prompt_pure_vcs_info[branch] ]]; then
         if [[ ${prompt_pure_vcs_info[branch]//[[:space:]]} == (*"|merge"|"master") ]]; then
             git_color=160
         fi
         preprompt_parts+=("%F{$git_color}"'${prompt_pure_vcs_info[branch]}%F{1}${prompt_pure_git_dirty}%f')
     fi

Then here https://github.com/sindresorhus/pure/blob/master/pure.zsh#L434 I add all this probably not the best eficient way but gives the git output I need:

local GIT_STATE=""
local NUM_AHEAD="$(git log --oneline @{u}.. 2> /dev/null | wc -l | tr -d ' ')"
if [ "$NUM_AHEAD" -gt 0 ]; then
    GIT_STATE="$GIT_STATE (+$NUM_AHEAD)"
fi

local NUM_BEHIND="$(git log --oneline ..@{u} 2> /dev/null | wc -l | tr -d ' ')"
if [ "$NUM_BEHIND" -gt 0 ]; then
    if [[ -n $GIT_STATE ]]; then
        GIT_STATE="$GIT_STATE"
    fi
    GIT_STATE="$GIT_STATE (-$NUM_BEHIND)"
fi

local GIT_STATUS="$(git status --porcelain | awk -v ORS=", " 'NR>0{arr[$1]++}END{for (a in arr) print a, arr[a]}' | sed 's/, $//g')"
[[ ! -z "${GIT_STATUS// }" ]] && GIT_STATE="$GIT_STATE %F{5}[$GIT_STATUS]"

if ! git diff --cached --quiet 2> /dev/null; then
    GIT_STATE="$GIT_STATE %F{7}[staged]"
fi

Just in case this is my full modified version: https://github.com/nbari/dotfiles/blob/master/my-dotfiles/.zsh/functions/prompt_pure_setup, heavily using it within tmux and vim, any improvements to fix this would be higly apreciated

@mafredri I use SSH but my SSH key is in github already. Here is a screenshot of me trying it with pure - master

image

Let me know if this problem is a separate problem and I can open a separate issue.

I'm also experiencing issues with the asynchronous git status, but mine is quite random and I haven't determined the steps necessary to reproduce. In my case, it almost always shows the correct branch and the fact that I'm in a repo, but occasionally it will not display the proper up/down arrow or *. For example, I just committed and pushed changes to a remote, but even after pushing, there remained an up arrow signifying that I needed to push. A git status confirmed that my working tree was indeed clean and I was up to date with origin. On another occasion, no down arrow appeared, yet the remote had updates that I needed to pull. This has been occurring intermittently since updating to the latest Pure, although I've also updated many other things so it's impossible to say.

The quick fix is to close the terminal window and open a new one.

For reference:

  • Pure version: 1.8.0
  • NPM version: 6.4.1
  • Git version: 2.19.0
  • ZSH version: 5.6.2
  • Terminal program & version: iTerm 3.2.1
  • Operating system: macOS Sierra 10.13.6
  • ZSH framework: oh-my-zsh (updated every week or two, or when prompted)

Could you try the following change?

diff --git a/pure.zsh b/pure.zsh
index a313c83..671da83 100644
--- a/pure.zsh
+++ b/pure.zsh
diff --git a/pure.zsh b/pure.zsh
index a313c83..671da83 100644
--- a/pure.zsh
+++ b/pure.zsh
@@ -385,6 +385,8 @@ prompt_pure_async_callback() {
    local job=$1 code=$2 output=$3 exec_time=$4 next_pending=$6
    local do_render=0

+   [[ -n $5 ]] && print "\nERROR($1): $5\n"
+
    case $job in
        prompt_pure_async_vcs_info)
            local -A info

Does it report any errors? Alternatively, you can try to run zsh with zsh -x and inspect the output generated by cd:in into the folder.

@mattgabor I had the same issue but I solved it by moving my plugin sections (zplug) to the top of my ~/.zshrc file instead at having it at the bottom. Hope it helps!

@mafredri not sure what you mean with the first two diffs --- a/pure.zsh +++ b/pure.zsh but I added that log to prompt_pure_async_callback and ran zsh -x and here's the output:

async:267 @_async_zle_watcher:1> setopt localoptions noshwordsplit
+ async:268 @_async_zle_watcher:2> typeset -gA ASYNC_PTYS ASYNC_CALLBACKS
+ async:269 @_async_zle_watcher:3> local worker=prompt_pure
+ async:270 @_async_zle_watcher:4> local callback=prompt_pure_async_callback
+ async:272 @_async_zle_watcher:6> [[ -n prompt_pure_async_callback ]]
+ async:273 @_async_zle_watcher:7> async_process_results prompt_pure prompt_pure_async_callback watcher
++ async:208 @async_process_results:1> setopt localoptions unset noshwordsplit noksharrays noposixidentifiers noposixstrings
++ async:210 @async_process_results:3> local worker=prompt_pure
++ async:211 @async_process_results:4> local callback=prompt_pure_async_callback
++ async:212 @async_process_results:5> local caller=watcher
++ async:213 @async_process_results:6> local -a items
++ async:214 @async_process_results:7> local null=$'\C-@' data
++ async:215 @async_process_results:8> integer -l len pos num_processed
++ async:217 @async_process_results:10> typeset -gA ASYNC_PROCESS_BUFFER
++ async:220 @async_process_results:13> zpty -r -t prompt_pure data
++ async:221 @async_process_results:14> ASYNC_PROCESS_BUFFER[$worker]+='prompt_pure_async_vcs_info 0 branch\ master\ top\ /Users/mattgabor/Developer/macstart 0.0667970181'
++ async:222 @async_process_results:15> len=196
++ async:223 @async_process_results:16> pos=197
++ async:226 @async_process_results:19> ((  ! len  ))
++ async:226 @async_process_results:19> ((  pos > len  ))
++ async:227 @async_process_results:20> continue
++ async:220 @async_process_results:13> zpty -r -t prompt_pure data
++ async:256 @async_process_results:49> ((  num_processed  ))
++ async:259 @async_process_results:52> [[ watcher = trap || watcher = watcher ]]
++ async:259 @async_process_results:52> return 0


@mattgabor it's only one diff, I accidentally duplicated the header. That said, your output from zsh -x looks incorrect, but I would probably require more output to figure out what's wrong since that's only a small snapshot. (PS. The patch was intended to be used without zsh -x, to see if there are any errors during regular use of Pure.)

Here's what the same output should look like when working correctly:

+ async:295 @_async_zle_watcher:1> setopt localoptions noshwordsplit
+ async:296 @_async_zle_watcher:2> typeset -gA ASYNC_PTYS ASYNC_CALLBACKS
+ async:297 @_async_zle_watcher:3> local worker=prompt_pure
+ async:298 @_async_zle_watcher:4> local callback=prompt_pure_async_callback
+ async:300 @_async_zle_watcher:6> [[ -n prompt_pure_async_callback ]]
+ async:301 @_async_zle_watcher:7> async_process_results prompt_pure prompt_pure_async_callback watcher
++ async:233 @async_process_results:1> setopt localoptions unset noshwordsplit noksharrays noposixidentifiers noposixstrings
++ async:235 @async_process_results:3> local worker=prompt_pure
++ async:236 @async_process_results:4> local callback=prompt_pure_async_callback
++ async:237 @async_process_results:5> local caller=watcher
++ async:238 @async_process_results:6> local -a items
++ async:239 @async_process_results:7> local null=$'\C-@' data
++ async:240 @async_process_results:8> integer -l len pos num_processed has_next
++ async:242 @async_process_results:10> typeset -gA ASYNC_PROCESS_BUFFER
++ async:245 @async_process_results:13> zpty -r -t prompt_pure data
++ async:246 @async_process_results:14> ASYNC_PROCESS_BUFFER[$worker]+=$'\C-@prompt_pure_async_vcs_info 0 branch\\ master\\ pwd\\ /Users/maf/Projects/pure\\ top\\ /Users/maf/Projects/zeet/modules/pure 0.0590150356 \'\'\C-@'
++ async:247 @async_process_results:15> len=136
++ async:248 @async_process_results:16> pos=1
++ async:251 @async_process_results:19> ((  ! len  ))
++ async:251 @async_process_results:19> ((  pos > len  ))
++ async:255 @async_process_results:23> ((  pos <= len  ))
++ async:258 @async_process_results:26> items=( '' )
++ async:261 @async_process_results:29> ASYNC_PROCESS_BUFFER[$worker]=$'prompt_pure_async_vcs_info 0 branch\\ master\\ pwd\\ /Users/maf/Projects/pure\\ top\\ /Users/maf/Projects/zeet/modules/pure 0.0590150356 \'\'\C-@'
++ async:263 @async_process_results:31> len=135
++ async:264 @async_process_results:32> ((  len > 1  ))
++ async:265 @async_process_results:33> pos=135
++ async:268 @async_process_results:36> has_next=1
++ async:269 @async_process_results:37> ((  1 == 5  ))
++ async:273 @async_process_results:41> [[ -z '' ]]
++ async:255 @async_process_results:23> ((  pos <= len  ))
++ async:258 @async_process_results:26> items=( prompt_pure_async_vcs_info 0 'branch master pwd /Users/maf/Projects/pure top /Users/maf/Projects/zeet/modules/pure' 0.0590150356 '' )
++ async:261 @async_process_results:29> ASYNC_PROCESS_BUFFER[$worker]=''
++ async:263 @async_process_results:31> len=0
++ async:264 @async_process_results:32> ((  len > 1  ))
++ async:268 @async_process_results:36> has_next=0
++ async:269 @async_process_results:37> ((  5 == 5  ))
++ async:270 @async_process_results:38> items+=( 0 )
++ async:271 @async_process_results:39> prompt_pure_async_callback prompt_pure_async_vcs_info 0 'branch master pwd /Users/maf/Projects/pure top /Users/maf/Projects/zeet/modules/pure' 0.0590150356 '' 0

Notice how these are different:

++ async:221 @async_process_results:14> ASYNC_PROCESS_BUFFER[$worker]+='prompt_pure_async_vcs_info 0 branch\ master\ top\ /Users/mattgabor/Developer/macstart 0.0667970181'

vs

++ async:246 @async_process_results:14> ASYNC_PROCESS_BUFFER[$worker]+=$'\C-@prompt_pure_async_vcs_info 0 branch\\ master\\ pwd\\ /Users/maf/Projects/pure\\ top\\ /Users/maf/Projects/zeet/modules/pure 0.0590150356 \'\'\C-@'

Your output is missing:

  • null characters at beginning / end
  • shell quoting (\\ vs \)
  • pwd
  • stderr output (\'\' at end)

I even tried this on zsh-5.3, but I can't reproduce your issue. It might also help if you shared the output from setopt.

@ttamnedlog that does sound separate from this issue, please open a new one and let's investigate it there!

@mattgabor additionally, I can't reproduce your issue with oh-my-zsh master using your .zshrc. But then again I don't have access to the files you source and you seem to have custom plugins defined. For example, setting plugin=(zsh-syntax-highlighting) doesn't do syntax highlighting for me ¯\_(ツ)_/¯.

I tested this on another machine and I don't see the issue, so I think it's something in my end not pure's. Thanks for the help!

Hope you find a resolution! And please let us know if you do, it would be great to know if we can guard against it.

In my try to fix this, I came up with https://crates.io/crates/slick

@nbari, thanks for sharing, and glad you've found a solution that works for you. For us, rust isn't an option as we want portability. I have a WIP branch for zsh-async that implements async in a similar way (no-zpty). I haven't had time work on it but my plan is to implement it as an alternate backend.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

hyphaene picture hyphaene  Â·  9Comments

mattrixman picture mattrixman  Â·  5Comments

Rawnly picture Rawnly  Â·  9Comments

erusev picture erusev  Â·  4Comments

ELLIOTTCABLE picture ELLIOTTCABLE  Â·  11Comments