Zsh Mailing List Archive
Messages sorted by: Reverse Date, Date, Thread, Author

Re: Look for git info in background




Hi,

Apologies for resurrecting such an old thread ;-) However, on the same topic rather than using vcs_info is it also possible to run a python script in the background to update the prompt e.g.

https://github.com/olivierverdier/zsh-git-prompt/blob/master/zshrc.sh#L42

where PROMPT might be

PROMPT='%m$(git_super_status) $ '

It wasn't quite clear to me (sorry :-( ) how one might/could use coproc in this scenario.

Thanks

Nick


On 17/02/14 02:20, Bart Schaefer wrote:
On Feb 17,  1:05am, Teto wrote:
}
} I would like to display the prompt as soon as I know if the folder is
} a git repo or not so that I can enter commands in the prompt. I would
} like zsh to retrieve that info (number of commtis ahead of upstream
} etc...) in background and update my prompt when the information
} becomes available.
}
} has anyone some code for that, I couldn't find anything ?

Hmm.  Something like this:

   autoload -Uz vcs_info

   vcs_update_info () {
     eval $(read -rE -u$1)		# Receive and run typeset
     zle -F $1				# Remove the handler
     exec {1}>&-				# Close the descriptor
     zle reset-prompt
   }
   zle -N vcs_update_info

   chpwd() {
     if zle -l vcs_update_info
     then
       typeset -g vcs_info_msg_0_= vcs_info_fd=
     fi
   }

   precmd() {
     if zle -l vcs_update_info
     then
       # NO_monitor / disown is to silence background job notices
       setopt localoptions NO_monitor
       coproc {
         sleep 1				# Assure disown runs first
         vcs_info			# Populate vcs_info_msg_0_
         typeset -p vcs_info_msg_0_	# Send typeset to parent
       }
       disown %${(k)^jobtexts[(R)*vcs_info*]}
       exec {vcs_info_fd}<&p		# Get descriptor for handler
       zle -F -w $vcs_info_fd vcs_update_info
     fi
   }

Then set up your prompts to include $vcs_info_msg_0_ as you normally
would.

Aside to zsh-workers:  It's generally a good thing that the coproc
mechanism now uses the job tables, etc., but it would be nice if it
could be made to shut up about the jobs starting/finishing without
having to disable the monitor and notify options entirely.




Messages sorted by: Reverse Date, Date, Thread, Author