1
0
Fork 0

Switch to an alternative method of async git in the sorin prompt

pull/1805/head
Kaleb Elwert 5 years ago
parent 1b99be879c
commit e07027821b

@ -32,29 +32,25 @@
# Load dependencies. # Load dependencies.
pmodload 'helper' pmodload 'helper'
function prompt_sorin_async_callback { function prompt_sorin_async_git_callback {
case $1 in # We can safely split on ':' because it isn't allowed in ref names.
prompt_sorin_async_git) IFS=':' read _git_target _git_post_target <<<"$3"
# We can safely split on ':' because it isn't allowed in ref names.
IFS=':' read _git_target _git_post_target <<<"$3" # The target actually contains 3 space separated possibilities, so we need to
# make sure we grab the first one.
# The target actually contains 3 space separated possibilities, so we need to _git_target=$(coalesce ${(@)${(z)_git_target}})
# make sure we grab the first one.
_git_target=$(coalesce ${(@)${(z)_git_target}}) if [[ -z "$_git_target" ]]; then
# No git target detected, flush the git fragment and redisplay the prompt.
if [[ -z "$_git_target" ]]; then if [[ -n "$_prompt_sorin_git" ]]; then
# No git target detected, flush the git fragment and redisplay the prompt. _prompt_sorin_git=''
if [[ -n "$_prompt_sorin_git" ]]; then zle && zle reset-prompt
_prompt_sorin_git='' fi
zle && zle reset-prompt else
fi # Git target detected, update the git fragment and redisplay the prompt.
else _prompt_sorin_git="${_git_target}${_git_post_target}"
# Git target detected, update the git fragment and redisplay the prompt. zle && zle reset-prompt
_prompt_sorin_git="${_git_target}${_git_post_target}" fi
zle && zle reset-prompt
fi
;;
esac
} }
function prompt_sorin_async_git { function prompt_sorin_async_git {
@ -66,19 +62,21 @@ function prompt_sorin_async_git {
} }
function prompt_sorin_async_tasks { function prompt_sorin_async_tasks {
# Initialize async worker. This needs to be done here and not in # If we've got a pending request, cancel it
# prompt_sorin_setup so the git formatting can be overridden by other prompts. if [[ -n "$_prompt_sorin_async_fd" ]] && { true <&$_prompt_sorin_async_fd } 2>/dev/null; then
if (( !${prompt_prezto_async_init:-0} )); then # Close the file descriptor and remove the handler
async_start_worker prompt_sorin -n exec {_prompt_sorin_async_fd}<&-
async_register_callback prompt_sorin prompt_sorin_async_callback zle -F $_prompt_sorin_async_fd
typeset -g prompt_prezto_async_init=1
fi fi
# Kill the old process of slow commands if it is still running. # Fork a process to fetch the git info and open a pipe to read from it
async_flush_jobs prompt_sorin exec {_prompt_sorin_async_fd}< <(
# Fetch and print the suggestion
prompt_sorin_async_git "$PWD"
)
# Compute slow commands in the background. # When the fd is readable, call the response handler
async_job prompt_sorin prompt_sorin_async_git "$PWD" zle -F "$_prompt_sorin_async_fd" prompt_sorin_async_callback
} }
function prompt_sorin_precmd { function prompt_sorin_precmd {
@ -113,7 +111,6 @@ function prompt_sorin_setup {
# Load required functions. # Load required functions.
autoload -Uz add-zsh-hook autoload -Uz add-zsh-hook
autoload -Uz async && async
# Add hook for calling git-info before each command. # Add hook for calling git-info before each command.
add-zsh-hook precmd prompt_sorin_precmd add-zsh-hook precmd prompt_sorin_precmd

Loading…
Cancel
Save