prompt: update sorin prompt async usage to be closer to pure

main
Kaleb Elwert 7 years ago
parent f02dc1af57
commit e159c1a439

@ -32,25 +32,29 @@
# Load dependencies. # Load dependencies.
pmodload 'helper' pmodload 'helper'
function prompt_sorin_git_info { function prompt_sorin_async_callback {
# We can safely split on ':' because it isn't allowed in ref names. case $1 in
IFS=':' read _git_target _git_post_target <<<"$3" prompt_sorin_async_git)
# We can safely split on ':' because it isn't allowed in ref names.
# The target actually contains 3 space separated possibilities, so we need to IFS=':' read _git_target _git_post_target <<<"$3"
# make sure we grab the first one.
_git_target=$(coalesce ${(@)${(z)_git_target}}) # The target actually contains 3 space separated possibilities, so we need to
# make sure we grab the first one.
if [[ -z "$_git_target" ]]; then _git_target=$(coalesce ${(@)${(z)_git_target}})
# No git target detected, flush the git fragment and redisplay the prompt.
if [[ -n "$_prompt_sorin_git" ]]; then if [[ -z "$_git_target" ]]; then
_prompt_sorin_git='' # No git target detected, flush the git fragment and redisplay the prompt.
zle && zle reset-prompt if [[ -n "$_prompt_sorin_git" ]]; then
fi _prompt_sorin_git=''
else zle && zle reset-prompt
# Git target detected, update the git fragment and redisplay the prompt. fi
_prompt_sorin_git="${_git_target}${_git_post_target}" else
zle && zle reset-prompt # Git target detected, update the git fragment and redisplay the prompt.
fi _prompt_sorin_git="${_git_target}${_git_post_target}"
zle && zle reset-prompt
fi
;;
esac
} }
function prompt_sorin_async_git { function prompt_sorin_async_git {
@ -61,6 +65,22 @@ function prompt_sorin_async_git {
fi fi
} }
function prompt_sorin_async_tasks {
# Initialize async worker. This needs to be done here and not in
# prompt_sorin_setup so the git formatting can be overridden by other prompts.
if (( !${prompt_prezto_async_init:-0} )); then
async_start_worker prompt_sorin -n
async_register_callback prompt_sorin prompt_sorin_async_callback
typeset -g prompt_prezto_async_init=1
fi
# Kill the old process of slow commands if it is still running.
async_flush_jobs async_sorin_git
# Compute slow commands in the background.
async_job async_sorin_git prompt_sorin_async_git "$PWD"
}
function prompt_sorin_precmd { function prompt_sorin_precmd {
setopt LOCAL_OPTIONS setopt LOCAL_OPTIONS
unsetopt XTRACE KSH_ARRAYS unsetopt XTRACE KSH_ARRAYS
@ -68,9 +88,6 @@ function prompt_sorin_precmd {
# Format PWD. # Format PWD.
_prompt_sorin_pwd=$(prompt-pwd) _prompt_sorin_pwd=$(prompt-pwd)
# Kill the old process of slow commands if it is still running.
async_flush_jobs async_sorin_git
# Handle updating git data. We also clear the git prompt data if we're in a # Handle updating git data. We also clear the git prompt data if we're in a
# different git root now. # different git root now.
if (( $+functions[git-dir] )); then if (( $+functions[git-dir] )); then
@ -81,14 +98,12 @@ function prompt_sorin_precmd {
fi fi
fi fi
# Run python info (this should be fast and not require any async) # Run python info (this should be fast and not require any async)
if (( $+functions[python-info] )); then if (( $+functions[python-info] )); then
python-info python-info
fi fi
# Compute slow commands in the background. prompt_sorin_async_tasks
async_job async_sorin_git prompt_sorin_async_git "$PWD"
} }
function prompt_sorin_setup { function prompt_sorin_setup {
@ -139,8 +154,6 @@ function prompt_sorin_setup {
zstyle ':prezto:module:python:info:virtualenv' format '%f%F{3}(%v)%F{7} ' zstyle ':prezto:module:python:info:virtualenv' format '%f%F{3}(%v)%F{7} '
# Get the async worker set up # Get the async worker set up
async_start_worker async_sorin_git -n
async_register_callback async_sorin_git prompt_sorin_git_info
_sorin_cur_git_root='' _sorin_cur_git_root=''
_prompt_sorin_git='' _prompt_sorin_git=''

Loading…
Cancel
Save