@ -525,259 +525,262 @@ function gitstatus_start"${1:-}"() {
local -i lock_fd resp_fd stderr_fd
local -i lock_fd resp_fd stderr_fd
local file_prefix xtrace = /dev/null daemon_log = /dev/null
local file_prefix xtrace = /dev/null daemon_log = /dev/null
if ( ( _GITSTATUS_STATE_$name ) ) ; then
( ( async ) ) && return
( ( _GITSTATUS_STATE_$name = = 2 ) ) && return
lock_fd = _GITSTATUS_LOCK_FD_$name
resp_fd = _GITSTATUS_RESP_FD_$name
xtrace = ${ (P) ${ :- GITSTATUS_XTRACE_ $name } }
daemon_log = ${ (P) ${ :- GITSTATUS_DAEMON_LOG_ $name } }
file_prefix = ${ (P) ${ :- _GITSTATUS_FILE_PREFIX_ $name } }
else
typeset -gi _GITSTATUS_START_COUNTER
local log_level = $GITSTATUS_LOG_LEVEL
local file_prefix = ${ ${ TMPDIR :- /tmp } : A } /gitstatus.$name .$EUID
file_prefix += .$sysparams [ pid] .$EPOCHSECONDS .$(( + + _GITSTATUS_START_COUNTER))
( ( GITSTATUS_ENABLE_LOGGING ) ) && : ${ log_level : =INFO }
if [ [ -n $log_level ] ] ; then
xtrace = $file_prefix .xtrace.log
daemon_log = $file_prefix .daemon.log
fi
args += ( -v ${ log_level :- FATAL } )
typeset -g GITSTATUS_XTRACE_$name = $xtrace
typeset -g GITSTATUS_DAEMON_LOG_$name = $daemon_log
typeset -g _GITSTATUS_FILE_PREFIX_$name = $file_prefix
typeset -gi _GITSTATUS_CLIENT_PID_$name = "sysparams[pid]"
typeset -gi _GITSTATUS_DIRTY_MAX_INDEX_SIZE_$name = dirty_max_index_size
fi
( ) {
if [ [ $xtrace != /dev/null && -o no_xtrace ] ] ; then
exec { stderr_fd} >& 2 || return
exec 2>>$xtrace || return
setopt xtrace
fi
setopt monitor || return
{
if ( ( _GITSTATUS_STATE_$name ) ) ; then
if ( ( ! _GITSTATUS_STATE_$name ) ) ; then
( ( async ) ) && return
if [ [ -r /proc/version && " $( </proc/version) " = = *Microsoft* ] ] ; then
( ( _GITSTATUS_STATE_$name = = 2 ) ) && return
lock_fd = -1
lock_fd = _GITSTATUS_LOCK_FD_$name
else
resp_fd = _GITSTATUS_RESP_FD_$name
print -rn >$file_prefix .lock || return
xtrace = ${ (P) ${ :- GITSTATUS_XTRACE_ $name } }
zsystem flock -f lock_fd $file_prefix .lock || return
daemon_log = ${ (P) ${ :- GITSTATUS_DAEMON_LOG_ $name } }
[ [ $lock_fd = = <1-> ] ] || return
file_prefix = ${ (P) ${ :- _GITSTATUS_FILE_PREFIX_ $name } }
else
typeset -gi _GITSTATUS_START_COUNTER
local log_level = $GITSTATUS_LOG_LEVEL
local file_prefix = ${ ${ TMPDIR :- /tmp } : A } /gitstatus.$name .$EUID
file_prefix += .$sysparams [ pid] .$EPOCHSECONDS .$(( + + _GITSTATUS_START_COUNTER))
( ( GITSTATUS_ENABLE_LOGGING ) ) && : ${ log_level : =INFO }
if [ [ -n $log_level ] ] ; then
xtrace = $file_prefix .xtrace.log
daemon_log = $file_prefix .daemon.log
fi
fi
args += ( -v ${ log_level :- FATAL } )
typeset -g GITSTATUS_XTRACE_$name = $xtrace
typeset -g GITSTATUS_DAEMON_LOG_$name = $daemon_log
typeset -g _GITSTATUS_FILE_PREFIX_$name = $file_prefix
typeset -gi _GITSTATUS_CLIENT_PID_$name = "sysparams[pid]"
typeset -gi _GITSTATUS_DIRTY_MAX_INDEX_SIZE_$name = dirty_max_index_size
fi
typeset -gi _GITSTATUS_LOCK_FD_$name = lock_fd
( ) {
if [ [ $xtrace != /dev/null && -o no_xtrace ] ] ; then
if [ [ -n $USERPROFILE && -d /cygdrive && -d /proc/self/fd ] ] ; then
exec { stderr_fd} >& 2 || return
# Work around bugs in Cygwin 32-bit.
exec 2>>$xtrace || return
#
setopt xtrace
# This hangs:
#
# emulate -L zsh
# () { exec {fd}< $1 } <(:)
# =true # hangs here
#
# This hangs:
#
# sysopen -r -u fd <(:)
local -i fd
exec { fd} < <( _gitstatus_daemon$fsuf ) || return
{
[ [ -r /proc/self/fd/$fd ] ] || return
sysopen -r -o cloexec -u resp_fd /proc/self/fd/$fd || return
} always {
exec { fd} >& - || return
}
else
sysopen -r -o cloexec -u resp_fd <( _gitstatus_daemon$fsuf ) || return
fi
fi
typeset -gi GITSTATUS_DAEMON_PID_$name = " ${ sysparams [procsubstpid] :- -1 } "
setopt monitor || return
[ [ $resp_fd = = <1-> ] ] || return
typeset -gi _GITSTATUS_RESP_FD_$name = resp_fd
typeset -gi _GITSTATUS_STATE_$name = 1
fi
if ( ( ! async ) ) ; then
if ( ( ! _GITSTATUS_STATE_$name ) ) ; then
( ( _GITSTATUS_CLIENT_PID_$name = = sysparams[ pid] ) ) || return
if [ [ -r /proc/version && " $( </proc/version) " = = *Microsoft* ] ] ; then
lock_fd = -1
else
print -rn >$file_prefix .lock || return
zsystem flock -f lock_fd $file_prefix .lock || return
[ [ $lock_fd = = <1-> ] ] || return
fi
local pgid
typeset -gi _GITSTATUS_LOCK_FD_$name = lock_fd
while ( ( $# pgid < 20 ) ) ; do
[ [ -t $resp_fd ] ]
if [ [ -n $USERPROFILE && -d /cygdrive && -d /proc/self/fd ] ] ; then
sysread -s $(( 20 - $# pgid)) -t $timeout -i $resp_fd 'pgid[$#pgid+1]' || return
# Work around bugs in Cygwin 32-bit.
done
#
[ [ $pgid = = ' ' #<1-> ]] || return
# This hangs:
typeset -gi GITSTATUS_DAEMON_PID_$name = pgid
#
# emulate -L zsh
sysopen -w -o cloexec -u req_fd -- $file_prefix .fifo || return
# () { exec {fd}< $1 } <(:)
[ [ $req_fd = = <1-> ] ] || return
# =true # hangs here
typeset -gi _GITSTATUS_REQ_FD_$name = req_fd
#
# This hangs:
function _gitstatus_process_response_$name -$fsuf ( ) {
#
emulate -L zsh -o no_aliases -o extended_glob -o typeset_silent
# sysopen -r -u fd <(:)
local pair = ${ ${ (%) :- %N } #_gitstatus_process_response_ }
local -i fd
local name = ${ pair %%-* }
exec { fd} < <( _gitstatus_daemon$fsuf ) || return
local fsuf = ${ pair #*- }
{
if ( ( ARGC = = 1 ) ) ; then
[ [ -r /proc/self/fd/$fd ] ] || return
_gitstatus_process_response$fsuf $name 0 ''
sysopen -r -o cloexec -u resp_fd /proc/self/fd/$fd || return
} always {
exec { fd} >& - || return
}
else
else
gitstatus_stop$fsuf $name
sysopen -r -o cloexec -u resp_fd <( _gitstatus_daemon$fsuf ) || return
fi
fi
}
if ! zle -F $resp_fd _gitstatus_process_response_$name -$fsuf ; then
typeset -gi GITSTATUS_DAEMON_PID_$name = " ${ sysparams [procsubstpid] :- -1 } "
unfunction _gitstatus_process_response_$name -$fsuf
return 1
[ [ $resp_fd = = <1-> ] ] || return
typeset -gi _GITSTATUS_RESP_FD_$name = resp_fd
typeset -gi _GITSTATUS_STATE_$name = 1
fi
fi
function _gitstatus_cleanup_$name -$fsuf ( ) {
if ( ( ! async ) ) ; then
emulate -L zsh -o no_aliases -o extended_glob -o typeset_silent
local pair = ${ ${ (%) :- %N } #_gitstatus_cleanup_ }
local name = ${ pair %%-* }
local fsuf = ${ pair #*- }
( ( _GITSTATUS_CLIENT_PID_$name = = sysparams[ pid] ) ) || return
( ( _GITSTATUS_CLIENT_PID_$name = = sysparams[ pid] ) ) || return
gitstatus_stop$fsuf $name
}
if ! add-zsh-hook zshexit _gitstatus_cleanup_$name -$fsuf ; then
unfunction _gitstatus_cleanup_$name -$fsuf
return 1
fi
print -nru $req_fd -- $'hello\x1f\x1e' || return
local pgid
local expected = $'hello\x1f0\x1e' actual
while ( ( $# pgid < 20 ) ) ; do
if ( ( $+functions[ p10k] ) ) && [ [ ! -t 1 && ! -t 0 ] ] ; then
[ [ -t $resp_fd ] ]
local -F deadline = 'EPOCHREALTIME + 4'
sysread -s $(( 20 - $# pgid)) -t $timeout -i $resp_fd 'pgid[$#pgid+1]' || return
else
done
local -F deadline = '1'
[ [ $pgid = = ' ' #<1-> ]] || return
fi
typeset -gi GITSTATUS_DAEMON_PID_$name = pgid
while true; do
[ [ -t $resp_fd ] ]
sysopen -w -o cloexec -u req_fd -- $file_prefix .fifo || return
sysread -s 1 -t $timeout -i $resp_fd actual || return
[ [ $req_fd = = <1-> ] ] || return
[ [ $actual = = h ] ] && break
typeset -gi _GITSTATUS_REQ_FD_$name = req_fd
[ [ $actual = = . ] ] || return
( ( EPOCHREALTIME < deadline ) ) && continue
print -nru $req_fd -- $'hello\x1f\x1e' || return
if ( ( deadline > 0 ) ) ; then
local expected = $'hello\x1f0\x1e' actual
deadline = 0
if ( ( $+functions[ p10k] ) ) && [ [ ! -t 1 && ! -t 0 ] ] ; then
if ( ( stderr_fd ) ) ; then
local -F deadline = 'EPOCHREALTIME + 4'
unsetopt xtrace
else
exec 2>& $stderr_fd { stderr_fd} >& -
local -F deadline = '1'
stderr_fd = 0
fi
fi
while true; do
if ( ( $+functions[ p10k] ) ) ; then
[ [ -t $resp_fd ] ]
p10k clear-instant-prompt || return
sysread -s 1 -t $timeout -i $resp_fd actual || return
fi
[ [ $actual = = h ] ] && break
if [ [ $name = = POWERLEVEL9K ] ] ; then
[ [ $actual = = . ] ] || return
local label = powerlevel10k
( ( EPOCHREALTIME < deadline ) ) && continue
else
if ( ( deadline > 0 ) ) ; then
local label = gitstatus
deadline = 0
if ( ( stderr_fd ) ) ; then
unsetopt xtrace
exec 2>& $stderr_fd { stderr_fd} >& -
stderr_fd = 0
fi
if ( ( $+functions[ p10k] ) ) ; then
p10k clear-instant-prompt || return
fi
if [ [ $name = = POWERLEVEL9K ] ] ; then
local label = powerlevel10k
else
local label = gitstatus
fi
if [ [ -t 2 ] ] ; then
local spinner = ( $'\b%3F-%f' $'\b%3F\\%f' $'\b%3F|%f' $'\b%3F/%f' )
print -Prnu2 -- " [%3F $label %f] fetching %2Fgitstatusd%f .. "
else
local spinner = ( '.' )
print -rnu2 -- " [ $label ] fetching gitstatusd .. "
fi
fi
fi
print -Prnu2 -- $spinner [ 1]
spinner = ( $spinner [ 2,-1] $spinner [ 1] )
done
if ( ( deadline = = 0 ) ) ; then
if [ [ -t 2 ] ] ; then
if [ [ -t 2 ] ] ; then
local spinner = ( $'\b%3F-%f' $'\b%3F\\%f' $'\b%3F|%f' $'\b%3F/%f' )
print -Pru2 -- $'\b[%2Fok%f]'
print -Prnu2 -- " [%3F $label %f] fetching %2Fgitstatusd%f .. "
else
else
local spinner = ( '.' )
print -ru2 -- ' [ok]'
print -rnu2 -- " [ $label ] fetching gitstatusd .. "
fi
if [ [ $xtrace != /dev/null && -o no_xtrace ] ] ; then
exec { stderr_fd} >& 2 || return
exec 2>>$xtrace || return
setopt xtrace
fi
fi
fi
fi
print -Prnu2 -- $spinner [ 1]
spinner = ( $spinner [ 2,-1] $spinner [ 1] )
done
if ( ( deadline = = 0 ) ) ; then
while ( ( $# actual < $# expected ) ) ; do
if [ [ -t 2 ] ] ; then
[ [ -t $resp_fd ] ]
print -Pru2 -- $'\b[%2Fok%f]'
sysread -s $(( $# expected - $# actual)) -t $timeout -i $resp_fd 'actual[$#actual+1]' || return
else
done
print -ru2 -- ' [ok]'
[ [ $actual = = $expected ] ] || return
function _gitstatus_process_response_$name -$fsuf ( ) {
emulate -L zsh -o no_aliases -o extended_glob -o typeset_silent
local pair = ${ ${ (%) :- %N } #_gitstatus_process_response_ }
local name = ${ pair %%-* }
local fsuf = ${ pair #*- }
[ [ $name = = POWERLEVEL9K && $fsuf = = _p9k_ ] ] && eval $__p9k_intro_base
if ( ( ARGC = = 1 ) ) ; then
_gitstatus_process_response$fsuf $name 0 ''
else
gitstatus_stop$fsuf $name
fi
}
if ! zle -F $resp_fd _gitstatus_process_response_$name -$fsuf ; then
unfunction _gitstatus_process_response_$name -$fsuf
return 1
fi
fi
if [ [ $xtrace != /dev/null && -o no_xtrace ] ] ; then
exec { stderr_fd} >& 2 || return
function _gitstatus_cleanup_$name -$fsuf ( ) {
exec 2>>$xtrace || return
emulate -L zsh -o no_aliases -o extended_glob -o typeset_silent
setopt xtrace
local pair = ${ ${ (%) :- %N } #_gitstatus_cleanup_ }
local name = ${ pair %%-* }
local fsuf = ${ pair #*- }
( ( _GITSTATUS_CLIENT_PID_$name = = sysparams[ pid] ) ) || return
gitstatus_stop$fsuf $name
}
if ! add-zsh-hook zshexit _gitstatus_cleanup_$name -$fsuf ; then
unfunction _gitstatus_cleanup_$name -$fsuf
return 1
fi
fi
fi
while ( ( $# actual < $# expected ) ) ; do
if ( ( lock_fd != -1 ) ) ; then
[ [ -t $resp_fd ] ]
zf_rm -- $file_prefix .lock || return
sysread -s $(( $# expected - $# actual)) -t $timeout -i $resp_fd 'actual[$#actual+1]' || return
zsystem flock -u $lock_fd || return
done
fi
[ [ $actual = = $expected ] ] || return
unset _GITSTATUS_LOCK_FD_$name
if ( ( lock_fd != -1 ) ) ; then
typeset -gi _GITSTATUS_STATE_$name = 2
zf_rm -- $file_prefix .lock || return
zsystem flock -u $lock_fd || return
fi
fi
unset _GITSTATUS_LOCK_FD_$name
}
} always {
typeset -gi _GITSTATUS_STATE_$name = 2
local -i err = $?
fi
( ( stderr_fd ) ) && exec 2>& $stderr_fd { stderr_fd} >& -
}
( ( err = = 0 ) ) && return
local -i err = $?
( ( stderr_fd ) ) && exec 2>& $stderr_fd { stderr_fd} >& -
( ( err = = 0 ) ) && return
gitstatus_stop$fsuf $name
gitstatus_stop$fsuf $name
setopt prompt_percent no_prompt_subst no_prompt_bang
setopt prompt_percent no_prompt_subst no_prompt_bang
print -Pru2 -- '[%F{red}ERROR%f]: gitstatus failed to initialize.'
print -ru2 -- ''
print -ru2 -- ''
print -Pru2 -- '[%F{red}ERROR%f]: gitstatus failed to initialize.'
print -ru2 -- ' Your Git prompt may disappear or become slow.'
if [ [ -s $xtrace ] ] ; then
print -ru2 -- ''
print -ru2 -- " The content of ${ (q-)xtrace } (gitstatus_start xtrace): "
print -Pru2 -- '%F{yellow}'
>& 2 awk '{print " " $0}' <$xtrace
print -Pru2 -- " %F{red} ^ this command failed ( $err )%f "
fi
if [ [ -s $daemon_log ] ] ; then
print -ru2 -- ''
print -ru2 -- ''
print -ru2 -- " The content of ${ (q-)daemon_log } (gitstatus daemon log): "
print -ru2 -- ' Your Git prompt may disappear or become slow.'
print -Pru2 -- '%F{yellow}'
if [ [ -s $xtrace ] ] ; then
>& 2 awk '{print " " $0}' <$daemon_log
print -ru2 -- ''
print -Pnru2 -- '%f'
print -ru2 -- " The content of ${ (q-)xtrace } (gitstatus_start xtrace): "
fi
print -Pru2 -- '%F{yellow}'
if [ [ $GITSTATUS_LOG_LEVEL = = DEBUG ] ] ; then
>& 2 awk '{print " " $0}' <$xtrace
print -ru2 -- ''
print -Pru2 -- " %F{red} ^ this command failed ( $err )%f "
print -ru2 -- ' Your system information:'
print -Pru2 -- '%F{yellow}'
print -ru2 -- " zsh: $ZSH_VERSION "
print -ru2 -- " uname -a: $( uname -a) "
print -Pru2 -- '%f'
print -ru2 -- ' If you need help, open an issue and attach this whole error message to it:'
print -ru2 -- ''
print -Pru2 -- ' %F{green}https://github.com/romkatv/gitstatus/issues/new%f'
else
print -ru2 -- ''
print -ru2 -- ' Run the following command to retry with extra diagnostics:'
print -Pru2 -- '%F{green}'
local env = "GITSTATUS_LOG_LEVEL=DEBUG"
if [ [ -n $GITSTATUS_NUM_THREADS ] ] ; then
env += " GITSTATUS_NUM_THREADS= ${ (q)GITSTATUS_NUM_THREADS } "
fi
fi
if [ [ -n $GITSTATUS_DAEMON ] ] ; then
if [ [ -s $daemon_log ] ] ; then
env += " GITSTATUS_DAEMON= ${ (q)GITSTATUS_DAEMON } "
print -ru2 -- ''
print -ru2 -- " The content of ${ (q-)daemon_log } (gitstatus daemon log): "
print -Pru2 -- '%F{yellow}'
>& 2 awk '{print " " $0}' <$daemon_log
print -Pnru2 -- '%f'
fi
fi
if [ [ -n $GITSTATUS_AUTO_INSTALL ] ] ; then
if [ [ $GITSTATUS_LOG_LEVEL = = DEBUG ] ] ; then
env += " GITSTATUS_AUTO_INSTALL= ${ (q)GITSTATUS_AUTO_INSTALL } "
print -ru2 -- ''
fi
print -ru2 -- ' Your system information:'
if [ [ -n $GITSTATUS_CACHE_DIR ] ] ; then
print -Pru2 -- '%F{yellow}'
env += " GITSTATUS_CACHE_DIR= ${ (q)GITSTATUS_CACHE_DIR } "
print -ru2 -- " zsh: $ZSH_VERSION "
print -ru2 -- " uname -a: $( uname -a) "
print -Pru2 -- '%f'
print -ru2 -- ' If you need help, open an issue and attach this whole error message to it:'
print -ru2 -- ''
print -Pru2 -- ' %F{green}https://github.com/romkatv/gitstatus/issues/new%f'
else
print -ru2 -- ''
print -ru2 -- ' Run the following command to retry with extra diagnostics:'
print -Pru2 -- '%F{green}'
local env = "GITSTATUS_LOG_LEVEL=DEBUG"
if [ [ -n $GITSTATUS_NUM_THREADS ] ] ; then
env += " GITSTATUS_NUM_THREADS= ${ (q)GITSTATUS_NUM_THREADS } "
fi
if [ [ -n $GITSTATUS_DAEMON ] ] ; then
env += " GITSTATUS_DAEMON= ${ (q)GITSTATUS_DAEMON } "
fi
if [ [ -n $GITSTATUS_AUTO_INSTALL ] ] ; then
env += " GITSTATUS_AUTO_INSTALL= ${ (q)GITSTATUS_AUTO_INSTALL } "
fi
if [ [ -n $GITSTATUS_CACHE_DIR ] ] ; then
env += " GITSTATUS_CACHE_DIR= ${ (q)GITSTATUS_CACHE_DIR } "
fi
print -nru2 -- " ${ env } gitstatus_start ${ (@q-)* } "
print -Pru2 -- '%f'
print -ru2 -- ''
local zshrc = ${ (D)ZDOTDIR :- ~ } /.zshrc
print -ru2 -- " If this command produces no output, add the following parameter to $zshrc : "
print -ru2 -- ''
print -Pru2 -- '%F{green} GITSTATUS_LOG_LEVEL=DEBUG%f'
print -ru2 -- ''
print -ru2 -- ' With this parameter gitstatus will print additional information on error.'
fi
fi
print -nru2 -- " ${ env } gitstatus_start ${ (@q-)* } "
}
print -Pru2 -- '%f'
print -ru2 -- ''
local zshrc = ${ (D)ZDOTDIR :- ~ } /.zshrc
print -ru2 -- " If this command produces no output, add the following parameter to $zshrc : "
print -ru2 -- ''
print -Pru2 -- '%F{green} GITSTATUS_LOG_LEVEL=DEBUG%f'
print -ru2 -- ''
print -ru2 -- ' With this parameter gitstatus will print additional information on error.'
fi
return err
}
}
# Stops gitstatusd if it's running.
# Stops gitstatusd if it's running.