1
0
Fork 0
mirror of https://github.com/romkatv/powerlevel10k.git synced 2024-11-16 09:50:06 +00:00

pull upstream changes from gitstatus

This commit is contained in:
romkatv 2019-03-15 19:14:39 +01:00
parent bad4e62e93
commit d6122d766c
2 changed files with 23 additions and 11 deletions

View file

@ -1,6 +1,4 @@
[[ -o interactive ]] || return
zmodload zsh/datetime || return
[[ -o interactive ]] && autoload -Uz add-zsh-hook && zmodload zsh/datetime || return
# Retrives status of a git repo from a directory under its working tree.
#
@ -91,8 +89,8 @@ function gitstatus_query() {
typeset -g $req_fd_var=$req_fd
typeset -g $resp_fd_var=$resp_fd
typeset -giH $client_pid_var=$client_pid
typeset -gfH _gitstatus_process_response_${name}() {
_gitstatus_process_response ${0#_gitstatus_process_response_} 0 ''
function _gitstatus_process_response_${name}() {
_gitstatus_process_response ${${(%)${:-%N}}#_gitstatus_process_response_} 0 ''
}
zle -F $resp_fd _gitstatus_process_response_${name}
}
@ -203,7 +201,7 @@ function gitstatus_start() {
[[ -f $daemon ]] || { echo "file not found: $daemon" >&2 && return 1 }
local req_fifo resp_fifo log
local -i req_fd resp_fd daemon_pid
local -i req_fd=-1 resp_fd=-1 daemon_pid=-1
function start() {
req_fifo=$(mktemp -u "${TMPDIR:-/tmp}"/gitstatus.$$.pipe.req.XXXXXXXXXX)
@ -212,8 +210,8 @@ function gitstatus_start() {
mkfifo $resp_fifo
exec {req_fd}<>$req_fifo
exec {resp_fd}<>$resp_fifo
typeset -gfH _gitstatus_process_response_${name}() {
_gitstatus_process_response ${0#_gitstatus_process_response_} 0 ''
function _gitstatus_process_response_${name}() {
_gitstatus_process_response ${${(%)${:-%N}}#_gitstatus_process_response_} 0 ''
}
zle -F $resp_fd _gitstatus_process_response_${name}
@ -242,6 +240,20 @@ function gitstatus_start() {
echo -nE $'hello\x1f\x1e' >&$req_fd
IFS='' read -r -d $'\x1e' -u $resp_fd -t $timeout reply
[[ $reply == $'hello\x1f0' ]]
function _gitstatus_cleanup_${name}() {
emulate -L zsh
local name=${${(%)${:-%N}}#_gitstatus_cleanup_}
local daemon_pid_var=GITSTATUS_DAEMON_PID_${name}
local req_fifo_var=_GITSTATUS_REQ_FIFO_${name}
local resp_fifo_var=_GITSTATUS_RESP_FIFO_${name}
local -i daemon_pid=${(P)daemon_pid_var}
local req_fifo=${(P)req_fifo_var}
local resp_fifo=${(P)resp_fifo_var}
[[ $daemon_pid -ge 0 ]] && kill -- -$daemon_pid &>/dev/null
rm -f $req_fifo $resp_fifo
}
add-zsh-hook zshexit _gitstatus_cleanup_${name}
}
start && {
@ -254,9 +266,9 @@ function gitstatus_start() {
typeset -giH _GITSTATUS_CLIENT_PID_${name}=$$
} || {
echo "gitstatus failed to initialize" >&2
[[ -n $daemon_pid ]] && kill $daemon_pid &>/dev/null || true
[[ -n $req_fd ]] && exec {req_fd}>&- || true
[[ -n $resp_fd ]] && { zle -F $resp_fd || true } && { exec {resp_fd}>&- || true}
[[ $daemon_pid -ge 0 ]] && kill -- -$daemon_pid &>/dev/null || true
[[ $req_fd -ge 0 ]] && exec {req_fd}>&- || true
[[ $resp_fd -ge 0 ]] && { zle -F $resp_fd || true } && { exec {resp_fd}>&- || true}
rm -f $req_fifo $resp_fifo
return 1
}