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

Re: Look for git info in background


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.


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.



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
       typeset -g vcs_info_msg_0_= vcs_info_fd=

   precmd() {
     if zle -l vcs_update_info
       # 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

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

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