zsh: treewide: minor fixes/style
This commit is contained in:
@@ -6,8 +6,8 @@
|
||||
## $1 - alternatives list
|
||||
## $2 - arguments to test command (USE WITH CAUTION!)
|
||||
z-alt-find() {
|
||||
local i c r t
|
||||
local -a v a
|
||||
local i c r t
|
||||
|
||||
v=( ${(@s:|:)1} )
|
||||
[ ${#v} = 0 ] && v=( "$1" )
|
||||
@@ -41,8 +41,9 @@ z-alt-find() {
|
||||
## $4 - function prologue
|
||||
## $5 - function epilogue
|
||||
z-alt-set-static() {
|
||||
local n t a r
|
||||
local -a s
|
||||
local n t a r
|
||||
|
||||
n="$1" ; t=''
|
||||
if [[ "$n" =~ '\|' ]] ; then
|
||||
t=${n:${MBEGIN}} ; n=${n:0:${MBEGIN}-1}
|
||||
@@ -59,6 +60,7 @@ z-alt-set-static() {
|
||||
s+=( 'return 127' )
|
||||
fi
|
||||
eval "$n () { ${s[@]} ; } ; typeset -g $n"
|
||||
|
||||
return $r
|
||||
}
|
||||
|
||||
@@ -69,8 +71,9 @@ z-alt-set-static() {
|
||||
## $4 - function prologue
|
||||
## $5 - function epilogue
|
||||
z-alt-set-dynamic() {
|
||||
local n t
|
||||
local -a s
|
||||
local n t
|
||||
|
||||
n="$1" ; t=''
|
||||
if [[ "$n" =~ '\|' ]] ; then
|
||||
t=${n:${MBEGIN}} ; n=${n:0:${MBEGIN}-1}
|
||||
|
@@ -2,13 +2,15 @@
|
||||
|
||||
z-time() {
|
||||
local a b elapsed result
|
||||
|
||||
a=${EPOCHREALTIME}
|
||||
"$@"
|
||||
result=$?
|
||||
b=$(( ${EPOCHREALTIME} - a ))
|
||||
b=$(( EPOCHREALTIME - a ))
|
||||
elapsed=$(z-ts-to-human "$b" 6)
|
||||
echo 1>&2
|
||||
echo "time took: ${elapsed}" 1>&2
|
||||
|
||||
return ${result}
|
||||
}
|
||||
|
||||
@@ -18,8 +20,10 @@ typeset -gA ZSHU_PS
|
||||
ZSHU_PS[cmd_threshold]=3
|
||||
|
||||
__z_cmdtime_precmd() {
|
||||
local t=${EPOCHREALTIME}
|
||||
# local t=${(%):-%D{%s.%9.}}
|
||||
local t x elapsed
|
||||
|
||||
t=${EPOCHREALTIME}
|
||||
# t=${(%):-%D{%s.%9.}}
|
||||
|
||||
ZSHU_PS[elapsed]=''
|
||||
(( ${+ZSHU_PS[cmd_ts]} )) || return
|
||||
@@ -27,13 +31,13 @@ __z_cmdtime_precmd() {
|
||||
t=$(( t - ${ZSHU_PS[cmd_ts]} ))
|
||||
unset "ZSHU_PS[cmd_ts]"
|
||||
|
||||
local x=$(( ${ZSHU_PS[cmd_threshold]} + 0 ))
|
||||
x=$(( ${ZSHU_PS[cmd_threshold]} + 0 ))
|
||||
[ "$x" = '0' ] && return
|
||||
|
||||
x=$(( t - x ))
|
||||
[ "${x:0:1}" = '-' ] && return
|
||||
|
||||
local elapsed=$(z-ts-to-human "$t")
|
||||
elapsed=$(z-ts-to-human "$t")
|
||||
ZSHU_PS[elapsed]=" %f[%B%F{yellow}+${elapsed}%b%f] "
|
||||
}
|
||||
|
||||
|
@@ -15,9 +15,10 @@ __z_compdump_invalidate() {
|
||||
}
|
||||
|
||||
__z_compdump_verify() {
|
||||
local i s
|
||||
|
||||
unset "ZSHU[compdump_refresh]"
|
||||
ZSHU[compdump_meta]='ZSH_VERSION ZSH_PATCHLEVEL FPATH PATH'
|
||||
local i s
|
||||
for i ( ${(s: :)ZSHU[compdump_meta]} ) ; do
|
||||
s=$(__z_compdump_print "$i")
|
||||
command grep -Fx -e "$s" "${ZSHU[f_compdump]}" &>/dev/null && continue
|
||||
@@ -28,6 +29,7 @@ __z_compdump_verify() {
|
||||
|
||||
__z_compdump_finalize() {
|
||||
local i
|
||||
|
||||
if (( ${+ZSHU[compdump_refresh]} )) ; then
|
||||
{
|
||||
echo
|
||||
@@ -41,11 +43,13 @@ __z_compdump_finalize() {
|
||||
}
|
||||
|
||||
__z_comp_bash() {
|
||||
local f p x
|
||||
|
||||
(( ${+commands[$1]} )) || return 1
|
||||
(( ${+_comps[$1]} )) && return 2
|
||||
(( ${+ZSHU[compdump_bash]} )) || return 3
|
||||
(( ${+2} )) && return 0
|
||||
local f p x
|
||||
|
||||
f=0
|
||||
for p ( /usr/share/bash-completion/completions ) ; do
|
||||
x="_$1" ; [ -s "$p/$x" ] && f=1 && break
|
||||
@@ -53,35 +57,47 @@ __z_comp_bash() {
|
||||
done
|
||||
[ "$f" = 0 ] && return 4
|
||||
complete -C "$x" "$1"
|
||||
|
||||
return 0
|
||||
}
|
||||
|
||||
__z_comp_external() {
|
||||
local f
|
||||
|
||||
(( ${+commands[$1]} )) || return 1
|
||||
(( ${+_comps[$1]} )) && return 2
|
||||
local f="${ZSHU[d_cache]}/completion/_$1"
|
||||
|
||||
f="${ZSHU[d_cache]}/completion/_$1"
|
||||
if ! [ -s "$f" ] ; then
|
||||
"$2" > "$f" || return 3
|
||||
fi
|
||||
autoload -Uz "_$1"
|
||||
|
||||
return 0
|
||||
}
|
||||
|
||||
__z_comp_system() {
|
||||
local d
|
||||
|
||||
(( ${+commands[$1]} )) || return 1
|
||||
(( ${+_comps[$1]} )) && return 2
|
||||
|
||||
for d ( $fpath ) ; do
|
||||
[ -s "$d/_$1" ] || continue
|
||||
autoload -Uz "_$1"
|
||||
return 0
|
||||
done ; unset d
|
||||
done
|
||||
|
||||
return 3
|
||||
}
|
||||
|
||||
## reload or new session are required to regenerate compcache
|
||||
z-comp-invalidate() {
|
||||
local f
|
||||
|
||||
[ -n "$1" ] || return 1
|
||||
local f="${ZSHU[d_cache]}/completion/_$1"
|
||||
|
||||
f="${ZSHU[d_cache]}/completion/_$1"
|
||||
[ -f "$f" ] || return 2
|
||||
command rm -f "$f" || return 3
|
||||
}
|
||||
|
@@ -21,10 +21,12 @@ z-git-test() {
|
||||
}
|
||||
|
||||
__z_git_pwd() {
|
||||
local p s last pfx
|
||||
|
||||
z-git-test || return
|
||||
local p=${(%):-%~}
|
||||
|
||||
p=${(%):-%~}
|
||||
[[ "$p" =~ '/.+' ]] || return
|
||||
local s pfx last
|
||||
s=$(__z_git rev-parse --show-prefix)
|
||||
s="${s%%/}"
|
||||
if [ -n "$s" ] ; then
|
||||
|
@@ -2,6 +2,7 @@
|
||||
|
||||
z-history() {
|
||||
local list
|
||||
|
||||
zparseopts -E l=list
|
||||
if [[ -n "$list" ]]; then
|
||||
builtin fc "$@"
|
||||
@@ -11,6 +12,8 @@ z-history() {
|
||||
}
|
||||
|
||||
z-grephist() {
|
||||
local what=$1 ; shift
|
||||
z-history -m "*${what}*" "$@"
|
||||
local x
|
||||
|
||||
x=$1 ; shift
|
||||
z-history -m "*${x}*" "$@"
|
||||
}
|
||||
|
@@ -20,16 +20,20 @@ ZSHU_PM[host]="%B%(!.%F{red}.%F{blue})${ZSHU[host]}%f%b"
|
||||
if autoload -Uz add-zsh-hook ; then
|
||||
|
||||
__z_pwd() {
|
||||
local p=${(%):-%~}
|
||||
local p pfx last
|
||||
|
||||
p=${(%):-%~}
|
||||
[[ "$p" =~ '/.+' ]] || return
|
||||
local pfx="${p:h}"
|
||||
pfx="${p:h}"
|
||||
pfx="${pfx%%/}"
|
||||
local last="${p:t}"
|
||||
last="${p:t}"
|
||||
ZSHU_PS[pwd]="%F{cyan}${pfx}/%B${last}%f%b"
|
||||
}
|
||||
|
||||
# ZSHU[pwd_hook]=''
|
||||
__z_pwd_hook() {
|
||||
local i
|
||||
|
||||
unset "ZSHU_PS[pwd]"
|
||||
for i ( ${(s: :)ZSHU[pwd_hook]} __z_pwd ) ; do
|
||||
"$i"
|
||||
|
@@ -27,7 +27,8 @@ function {
|
||||
typeset -gA ZSHU_RUN
|
||||
|
||||
z-run-test() {
|
||||
local key i
|
||||
local key v i
|
||||
|
||||
key=$1 ; shift
|
||||
v=0
|
||||
for i ( ${ZSHU_PARENTS_NAME} ) ; do
|
||||
|
@@ -4,8 +4,8 @@ typeset -Uga ZSHU_TERM_MISSING
|
||||
|
||||
z-ti-test() {
|
||||
local r i
|
||||
r=0
|
||||
|
||||
r=0
|
||||
for i ; do
|
||||
[ -z "$i" ] && continue
|
||||
if ! (( ${+terminfo[$i]} )) ; then
|
||||
|
@@ -1,12 +1,14 @@
|
||||
#!/bin/zsh
|
||||
|
||||
z-ts-to-human() {
|
||||
local t=$1
|
||||
local s=$(( int(t) ))
|
||||
local ns=$(( int((t - s) * (10**9)) ))
|
||||
local t s ns d h m f x
|
||||
|
||||
t=$1
|
||||
s=$(( int(t) ))
|
||||
ns=$(( int((t - s) * (10**9)) ))
|
||||
t=$s
|
||||
|
||||
local d=0 h=0 m=0
|
||||
d=0 h=0 m=0
|
||||
if [ $t -ge 86400 ] ; then
|
||||
d=$(( t / 86400 ))
|
||||
t=$(( t % 86400 ))
|
||||
@@ -20,10 +22,10 @@ z-ts-to-human() {
|
||||
t=$(( t % 60 ))
|
||||
fi
|
||||
|
||||
local f='%s.%6.'
|
||||
f='%s.%6.'
|
||||
f=$(strftime "$f" $t $ns)
|
||||
|
||||
local x=3
|
||||
x=3
|
||||
## keep math in sync with format above
|
||||
case "$2" in
|
||||
0) x=7 ;;
|
||||
@@ -35,5 +37,6 @@ z-ts-to-human() {
|
||||
[ $s -ge 60 ] && f="${m}m:$f"
|
||||
[ $s -ge 3600 ] && f="${h}h:$f"
|
||||
[ $s -ge 86400 ] && f="${d}d:$f"
|
||||
|
||||
echo "$f"
|
||||
}
|
||||
|
Reference in New Issue
Block a user