1
0

zsh: update
All checks were successful
ci/woodpecker/push/woodpecker Pipeline was successful

This commit is contained in:
2024-03-04 15:35:55 +03:00
parent 25123cece2
commit 8834da817c
20 changed files with 265 additions and 49 deletions

View File

@@ -48,11 +48,12 @@ __z_compdump_finalize() {
## TODO: refactor (e.g. buildah completion is a "bit" broken)
__z_comp_bash() {
# (( ${+commands[$1]} )) || return 127
local f p x
(( ${+commands[$1]} )) || return 1
(( ${+_comps[$1]} )) && return 2
(( ${+ZSHU[compdump_bash]} )) || return 3
(( ${+_comps[$1]} )) && return 1
(( ${+ZSHU[compdump_bash]} )) || return 2
(( ${+2} )) && return 0
f=0
@@ -60,7 +61,7 @@ __z_comp_bash() {
x="_$1" ; [ -s "$p/$x" ] && f=1 && break
x="$1" ; [ -s "$p/$x" ] && f=1 && break
done
[ "$f" = 0 ] && return 4
[ "$f" = 0 ] && return 3
complete -C "$x" "$1"
return 0
@@ -70,9 +71,9 @@ __z_comp_external() {
local c f
c="$1" ; shift
[ $# -gt 0 ] || return 1
(( ${+commands[$c]} )) || return 127
(( ${+commands[$c]} )) || return 2
[ $# -gt 0 ] || return 1
if ! (( ${+ZSHU_COMP_FORCE[$c]} )) ; then
(( ${+_comps[$c]} )) && return 0
@@ -82,7 +83,7 @@ __z_comp_external() {
if ! [ -s "$f" ] ; then
if ! "$@" > "$f" ; then
rm -f "$f"
return 3
return 2
fi
fi
# zcompile -zR "$f"
@@ -94,10 +95,11 @@ __z_comp_external() {
}
__z_comp_system() {
# (( ${+commands[$1]} )) || return 127
local d
(( ${+commands[$1]} )) || return 1
(( ${+_comps[$1]} )) && return 2
(( ${+_comps[$1]} )) && return 1
(( ${+ZSHU_COMP_FORCE[$c]} )) && return 0
@@ -113,12 +115,12 @@ __z_comp_system() {
return 0
done
fpath=( ${_fpath} )
return 3
return 2
}
## reload or new session are required to regenerate compcache
z-comp-invalidate() {
[ -n "$1" ] || return 1
[ -n "${1:?}" ]
# rm -f "${ZSHU[d_completion]}/_$1" "${ZSHU[d_compzwc]}/_$1.zwc" "${ZSHU[d_compzwc]}/$1.zwc"
rm -f "${ZSHU[d_completion]}/_$1"

33
.config/zsh/lib/csv.zsh Normal file
View File

@@ -0,0 +1,33 @@
#!/bin/zsh
## NB: set IFS manually
z-csv-select() {
local field value
field="${1:?}" value="${2:?}"
local line
local -a ary
while IFS='' read -rs line ; do
[ -n "${line}" ] || continue
ary=()
read -rs -A ary <<< "${line}"
[ "${ary[${field}]}" = "${value}" ] || continue
printf '%s' "${line}"
return 0
done
return 1
}
z-csv-field() {
local field
field="${1:?}"
local -a ary
read -rs -A ary
printf '%s' "${ary[${field}]}"
}

View File

@@ -21,7 +21,7 @@ __z_git_desc_tag() { __z_git describe --tags "$@" ; }
z-git-test() {
[ "${ZSHU_PS[git]}" = '1' ] || return 1
__z_git_avail || return 2
__z_git_avail || return $?
__z_git_is_repo || return 3

45
.config/zsh/lib/gpg.zsh Normal file
View File

@@ -0,0 +1,45 @@
#!/bin/zsh
z-gpgconf-comp-avail() {
(( ${+commands[gpgconf]} )) || return 127
local comp
comp="${1:?}"
local csv
csv=$(command gpgconf --list-components | IFS=':' z-csv-select 1 "${comp}")
[ -n "${csv}" ]
}
z-gpgconf-comp-opt-avail() {
(( ${+commands[gpgconf]} )) || return 127
local comp opt
comp="${1:?}" opt="${2:?}"
z-gpgconf-comp-avail "${comp}" || return $?
local csv
csv=$(command gpgconf --list-options "${comp}" | IFS=':' z-csv-select 1 "${opt}")
[ -n "${csv}" ]
}
## merely that command:
## gpgconf --list-options "$1" | awk -F: "/^$2:/{ print \$10 }"
z-gpgconf-getopt() {
(( ${+commands[gpgconf]} )) || return 127
local comp opt
comp="${1:?}" opt="${2:?}"
## not really necessary here
# z-gpgconf-comp-opt-avail "${comp}" "${opt}" || return $?
local csv
csv=$(command gpgconf --list-options "${comp}" | IFS=':' z-csv-select 1 "${opt}")
[ -n "${csv}" ] || return 1
local v
v=$(IFS=':' z-csv-field 10 <<< "${csv}")
printf '%s' "$v"
}

View File

@@ -1,10 +1,28 @@
#!/bin/zsh
z-proc-exists() {
[ -n "${1:?}" ]
while [ -n "${ZSHU[procfs]}" ] ; do
[ -d "${ZSHU[procfs]}" ] || return 1
[ -f "${ZSHU[procfs]}/$1/status" ]
return $?
done
ps -o 'pid=' -p "$1" >/dev/null 2>&1
}
typeset -Uga ZSHU_PARENTS_PID
typeset -ga ZSHU_PARENTS_NAME
function {
local i c g
local procfs
while [ -n "${ZSHU[procfs]}" ] ; do
[ -d "${ZSHU[procfs]}" ] || break
procfs=1 ; break
done
local i c x _unused
i=${PPID}
while : ; do
@@ -13,8 +31,32 @@ function {
[ "$i" = 1 ] && break
ZSHU_PARENTS_PID+=( $i )
read -r i c g <<< $(ps -o 'ppid=,comm=' -p "$i" 2>/dev/null)
c=
while [ "${procfs}" = 1 ] ; do
[ -f "${ZSHU[procfs]}/$i/cmdline" ] || break
read -d $'\0' -rs c <<< $(cat "${ZSHU[procfs]}/$i/cmdline")
break
done
if [ -z "$c" ] ; then
read -rs c _unused <<< "$(ps -o 'comm=' -p "$i" 2>/dev/null)"
fi
[ -n "$c" ] && ZSHU_PARENTS_NAME+=( "${c:t}" )
x=
while [ "${procfs}" = 1 ] ; do
[ -f "${ZSHU[procfs]}/$i/status" ] || break
# read -rs _unused x <<< "$(cat "${ZSHU[procfs]}/$i/status" | grep -F 'PPid:')"
while read -rs _unused c ; do
[ "${_unused}" = 'PPid:' ] || continue
x=$c ; break
done < "${ZSHU[procfs]}/$i/status"
break
done
if [ -z "$x" ] ; then
read -rs x _unused <<< "$(ps -o 'ppid=' -p "$i" 2>/dev/null)"
fi
i=$x
done
typeset -r ZSHU_PARENTS_PID ZSHU_PARENTS_NAME

View File

@@ -21,7 +21,7 @@ dotfiles-gen-gitignore() {
}
if [ -d .config/dotfiles/repo.git ] ; then
echo "NOT going to change dotfiles installation" >&2
return 1
return 2
fi
"$x" "$@"
}
@@ -55,9 +55,11 @@ z-update() {
z-reload() {
export ZDOTDIR="${ZSHU[d_zdot]}"
local r
exec -a "${ZSH_ARGZERO}" "${ZSH_NAME}" "${argv[@]}"
echo "unable to reload (something went wrong), code $?" >&2
return 1
r=$?
echo "unable to reload (something went wrong), code $r" >&2
return $r
}
## reload or new session are required to regenerate compcache

View File

@@ -0,0 +1,18 @@
#!/bin/zsh
z-systemctl() {
command systemctl --quiet --no-pager --lines=0 --no-ask-password "$@"
}
z-systemctl-status-rc() {
z-systemctl status "$@" >/dev/null 2>&1
}
z-systemctl-exists() {
z-systemctl-status-rc "$@"
case "$?" in
0 | 1 | 3 ) return 0 ;;
## also 4 = "no such unit"
* ) return 1 ;;
esac
}