Zsh Mailing List Archive
Messages sorted by:
Reverse Date,
Date,
Thread,
Author
Re: Look for git info in background
- X-seq: zsh-users 18467
- From: Bart Schaefer <schaefer@xxxxxxxxxxxxxxxx>
- To: zsh-users@xxxxxxx
- Subject: Re: Look for git info in background
- Date: Sun, 16 Feb 2014 18:20:21 -0800
- In-reply-to: <CADHp1NzyVdhBhZ=dLib+7mt_F+ZdTAb0EKkLMLJmrMcsA_-myg@mail.gmail.com>
- List-help: <mailto:zsh-users-help@zsh.org>
- List-id: Zsh Users List <zsh-users.zsh.org>
- List-post: <mailto:zsh-users@zsh.org>
- Mailing-list: contact zsh-users-help@xxxxxxx; run by ezmlm
- References: <CADHp1NzyVdhBhZ=dLib+7mt_F+ZdTAb0EKkLMLJmrMcsA_-myg@mail.gmail.com>
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