aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rwxr-xr-xgitstatus/bin/gitstatusd-linux-x86_64bin2118928 -> 2118928 bytes
-rw-r--r--gitstatus/gitstatus.plugin.zsh34
2 files changed, 23 insertions, 11 deletions
diff --git a/gitstatus/bin/gitstatusd-linux-x86_64 b/gitstatus/bin/gitstatusd-linux-x86_64
index 8e0a4658..536f39df 100755
--- a/gitstatus/bin/gitstatusd-linux-x86_64
+++ b/gitstatus/bin/gitstatusd-linux-x86_64
Binary files differ
diff --git a/gitstatus/gitstatus.plugin.zsh b/gitstatus/gitstatus.plugin.zsh
index ba48a99b..8b1acd5f 100644
--- a/gitstatus/gitstatus.plugin.zsh
+++ b/gitstatus/gitstatus.plugin.zsh
@@ -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
}