1
0
mirror of https://github.com/dcarrillo/prezto.git synced 2024-12-22 16:18:00 +00:00

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

This commit is contained in:
Kaleb Elwert 2017-11-11 15:18:31 -08:00
parent f02dc1af57
commit e159c1a439

View File

@ -32,7 +32,9 @@
# Load dependencies. # Load dependencies.
pmodload 'helper' pmodload 'helper'
function prompt_sorin_git_info { function prompt_sorin_async_callback {
case $1 in
prompt_sorin_async_git)
# We can safely split on ':' because it isn't allowed in ref names. # We can safely split on ':' because it isn't allowed in ref names.
IFS=':' read _git_target _git_post_target <<<"$3" IFS=':' read _git_target _git_post_target <<<"$3"
@ -51,6 +53,8 @@ function prompt_sorin_git_info {
_prompt_sorin_git="${_git_target}${_git_post_target}" _prompt_sorin_git="${_git_target}${_git_post_target}"
zle && zle reset-prompt zle && zle reset-prompt
fi 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=''