mirror of
https://github.com/ohmyzsh/ohmyzsh.git
synced 2026-04-03 04:20:01 +02:00
split out the async prompt code
This commit is contained in:
parent
6cb3bdbaff
commit
e67a982b52
2 changed files with 39 additions and 37 deletions
33
lib/async-git-prompt.zsh
Normal file
33
lib/async-git-prompt.zsh
Normal file
|
|
@ -0,0 +1,33 @@
|
|||
ASYNC_PROC=0
|
||||
function precmd() {
|
||||
function async() {
|
||||
# save to temp file
|
||||
printf "%s" "$(git_prompt_info)" > "${HOME}/.zsh_tmp_prompt"
|
||||
|
||||
# signal parent
|
||||
kill -s USR1 $$
|
||||
}
|
||||
|
||||
# do not clear RPROMPT, let it persist
|
||||
|
||||
# kill child if necessary
|
||||
if [[ "${ASYNC_PROC}" != 0 ]]; then
|
||||
kill -s HUP $ASYNC_PROC >/dev/null 2>&1 || :
|
||||
fi
|
||||
|
||||
# start background computation
|
||||
async &!
|
||||
ASYNC_PROC=$!
|
||||
}
|
||||
|
||||
function TRAPUSR1() {
|
||||
# read from temp file
|
||||
PROMPT="${PROMPT_START} $(cat ${HOME}/.zsh_tmp_prompt) ${PROMPT_END}"
|
||||
|
||||
# reset proc number
|
||||
ASYNC_PROC=0
|
||||
|
||||
# redisplay
|
||||
zle && zle reset-prompt
|
||||
}
|
||||
|
||||
Loading…
Add table
Add a link
Reference in a new issue