split out the async prompt code

This commit is contained in:
Yoav Weiss 2015-11-21 22:19:51 +02:00
commit e67a982b52
2 changed files with 39 additions and 37 deletions

33
lib/async-git-prompt.zsh Normal file
View 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
}

View file

@ -12,11 +12,12 @@ else
fi
fi
setopt prompt_subst
PROMPT="╭ ${user_host} %t ${current_dir} ${rvm_ruby}
PROMPT_START="╭ ${user_host} %t ${current_dir} ${rvm_ruby}"
PROMPT_END="
╰ %B$%b "
RPROMPT=""
PROMPT="${PROMPT_START} ${PROMPT_END}"
RPS1="${return_code}"
ZSH_THEME_GIT_PROMPT_PREFIX="%{$fg[yellow]%}"
@ -24,36 +25,4 @@ ZSH_THEME_GIT_PROMPT_SUFFIX=" %{$reset_color%}"
ZSH_THEME_GIT_PROMPT_CLEAN="✔"
ZSH_THEME_GIT_PROMPT_DIRTY="✗"
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="╭ ${user_host} %t ${current_dir} ${rvm_ruby} $(cat ${HOME}/.zsh_tmp_prompt)
╰ %B$%b "
# reset proc number
ASYNC_PROC=0
# redisplay
zle && zle reset-prompt
}
source $ZSH/lib/async-git-prompt.zsh