ohmyzsh/lib/async-git-prompt.zsh
2015-11-21 22:19:51 +02:00

33 lines
665 B
Bash

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
}