1
0

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

This commit is contained in:
Konstantin Demin 2024-03-04 15:35:55 +03:00
parent 25123cece2
commit 8834da817c
Signed by: krd
GPG Key ID: 1F33CB0BA4731BC6
20 changed files with 265 additions and 49 deletions

0
.cache/zsh/ssh/.keep Normal file
View File

View File

@ -2,6 +2,7 @@
!/.cache/zsh/compcache/.keep
!/.cache/zsh/completion/.keep
!/.cache/zsh/compzwc/.keep
!/.cache/zsh/ssh/.keep
!/.config/dotfiles/bin/.keep
!/.config/dotfiles/gen-gitignore.sh
!/.config/dotfiles/gitattributes
@ -48,13 +49,16 @@
!/.config/zsh/lib/alternatives.zsh
!/.config/zsh/lib/cmdtime.zsh
!/.config/zsh/lib/completion.zsh
!/.config/zsh/lib/csv.zsh
!/.config/zsh/lib/curl.zsh
!/.config/zsh/lib/git.zsh
!/.config/zsh/lib/gpg.zsh
!/.config/zsh/lib/history.zsh
!/.config/zsh/lib/prompt.zsh
!/.config/zsh/lib/pswalk.zsh
!/.config/zsh/lib/say-my.zsh
!/.config/zsh/lib/selfservice.zsh
!/.config/zsh/lib/systemd.zsh
!/.config/zsh/lib/term.zsh
!/.config/zsh/lib/time.zsh
!/.config/zsh/lib/title.zsh
@ -69,9 +73,11 @@
!/.config/zsh/opt/prompt.zsh
!/.config/zsh/rc.zsh
!/.config/zsh/rc/completion.zsh
!/.config/zsh/rc/gpg-agent.zsh
!/.config/zsh/rc/keyboard.zsh
!/.config/zsh/rc/pager.zsh
!/.config/zsh/rc/prompt.zsh
!/.config/zsh/rc/ssh-agent.zsh
!/.config/zsh/rc/terminal.zsh
!/.config/zsh/var/.keep
!/.gdbinit

View File

@ -12,19 +12,19 @@ alias pod-logs='podman logs '
sko-inspect() {
local i
i="${1:?}" ; shift
command skopeo inspect "docker://$i" "$@"
command skopeo inspect "$@" "docker://$i"
}
sko-list-tags() {
local i
i="${1:?}" ; shift
command skopeo list-tags "docker://$i" "$@"
command skopeo list-tags "$@" "docker://$i"
}
pod-dive() {
local i
i="${1:?}" ; shift
command dive "podman://$i" "$@"
command dive "$@" "podman://$i"
}
jq-visual() {

View File

@ -1,7 +1,7 @@
#!/bin/zsh
gpg-warmup() {
(( ${+commands[gpg]} )) || return 1
(( ${+commands[gpg]} )) || return 127
local t r

View File

@ -1,7 +1,7 @@
#!/bin/zsh
idle() {
[ -n "${1:?}" ] || return 1
[ -n "${1:?}" ]
local f
@ -17,7 +17,7 @@ idle() {
}
z-idle-ext() {
[ -n "${1:?}" ] || return 1
[ -n "${1:?}" ]
local -a s
@ -28,7 +28,7 @@ z-idle-ext() {
}
z-idle-int() {
[ -n "${1:?}" ] || return 1
[ -n "${1:?}" ]
## execute in subshell
(

View File

@ -1,24 +1,22 @@
#!/bin/zsh
kconf-set() {
[ -n "${1:?}" ] || return 1
local n=$1 v=$2
local n v
n="${1:?}" v=$2
shift 2
[ $# -gt 0 ] || return 2
[ $# -gt 0 ] || return 1
command grep -ElZ "^((CONFIG_)?$n=|# (CONFIG_)?$n is not set)" "$@" \
| xargs -0 -r sed -i -E -e "s/^(((CONFIG_)?$n)=.+|# ((CONFIG_)?$n) is not set)\$/\\2\\4=$v/"
}
kconf-unset() {
[ -n "${1:?}" ] || return 1
local n=$1
local n
n="${1:?}"
shift
[ $# -gt 0 ] || return 2
[ $# -gt 0 ] || return 1
command grep -ElZ "^(CONFIG_)?$n=" "$@" \
| xargs -0 -r sed -i -E -e "s/^((CONFIG_)?$n)=.+\$/# \\1 is not set/"

View File

@ -5,7 +5,7 @@ quilt-series-strip-comments() {
}
quilt-series-auto() {
[ -n "${1:?}" ] || return 1
[ -n "${1:?}" ]
find "$1/" -follow -type f -printf '%P\0' \
| sed -zEn '/\.(diff|patch)$/p' \
@ -13,16 +13,16 @@ quilt-series-auto() {
}
krd-quilt() {
[ -n "${1:?}" ] || return 1
(( $+commands[quilt] )) || return 127
(( $+commands[quilt] )) || return 2
[ -n "${1:?}" ]
local patchdir series tmp_series
if [ -d "$1" ] ; then
patchdir="$1/debian/patches"
if [ -d "${patchdir}" ] ; then
[ -f "${patchdir}/series" ] || return 3
[ -f "${patchdir}/series" ] || return 1
else
patchdir="$1"
fi
@ -34,7 +34,7 @@ krd-quilt() {
quilt-series-auto "${patchdir}" > "${series}"
fi
elif [ -f "$1" ] ; then
[ -s "$1" ] || return 3
[ -s "$1" ] || return 2
series="$1"
patchdir=${series:h}
@ -53,7 +53,7 @@ krd-quilt() {
command quilt pop -a ; echo
r=0
while read -r i ; do
while read -rs i ; do
[ -n "$i" ] || continue
k="${patchdir}/$i"

View File

@ -1,7 +1,9 @@
#!/bin/zsh
krd-debsrc() {
[ -n "${1:?}" ] || return 1
(( $+commands[deb-src-export] )) || return 127
[ -n "${1:?}" ]
local dstdir
case "$1" in
@ -13,21 +15,21 @@ krd-debsrc() {
}
krd-sbuild() {
[ -n "${1:?}" ] || return 1
[ -n "${2:?}" ] || return 1
(( $+commands[sbuild] )) || return 127
(( $+commands[xz] )) || return 127
(( $+commands[sbuild] )) || return 2
(( $+commands[xz] )) || return 2
[ -n "${1:?}" ]
[ -n "${2:?}" ]
local topdir
case "$1" in
*/* ) topdir="$1" ;;
* ) topdir="/tmp/$1" ;;
esac
[ -d "${topdir}" ] || return 3
[ -d "${topdir}" ] || return 1
local srcdir="${topdir}/src"
[ -d "${srcdir}" ] || return 3
[ -d "${srcdir}" ] || return 2
arch="$2"

View File

@ -86,3 +86,7 @@ function {
## last resort
ZSHU[host]=${ZSHU[host_name]}
}
case "${ZSHU[os_family]}" in
linux ) ZSHU[procfs]=/proc ;;
esac

View File

@ -2,11 +2,12 @@
z-gobin-fixup() {
(( ${+commands[go]} )) || return 0
local gobin
gobin=$(go env GOBIN)
gobin=$(command go env GOBIN)
if [ -z "${gobin}" ] ; then
local gopath
gopath=$(go env GOPATH)
gopath=$(command go env GOPATH)
[ -n "${gopath}" ] || return 1
[ -d "${gopath}" ] || return 0
gobin="${gopath}/bin"

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
}

View File

@ -0,0 +1,33 @@
#!/bin/zsh
z-gpg-agent() {
## don't bother with gpg agent socket if it already set
[ -z "${GPG_AGENT_INFO}" ] || return 0
(( ${+commands[gpg-agent]} )) || return 127
local u
for u in gpg-agent.{service,socket} ; do
z-systemctl-exists --user $u || continue
z-systemctl --user --now enable $u
done
(( ${+commands[gpgconf]} )) || return 127
local agent_sock
agent_sock=$(command gpgconf --list-dirs agent-socket) || return $?
[ -n "${agent_sock}" ] || return 3
export GPG_AGENT_INFO="${agent_sock}:0:1"
## don't bother with ssh agent socket if it already set
[ -z "${SSH_AUTH_SOCK}" ] || return 0
local want_ssh_agent ssh_auth_sock
want_ssh_agent=$(z-gpgconf-getopt gpg-agent enable-ssh-support)
if [ "${want_ssh_agent}" = 1 ] ; then
ssh_auth_sock=$(command gpgconf --list-dirs agent-ssh-socket) || return $?
[ -n "${ssh_auth_sock}" ] || return 5
export SSH_AUTH_SOCK="${ssh_auth_sock}"
fi
}

View File

@ -0,0 +1,29 @@
#!/bin/zsh
z-ssh-agent() {
while [ -n "${SSH_AGENT_PID}" ] ; do
z-proc-exists "${SSH_AGENT_PID}" || break
## don't bother with ssh agent socket if it already set
[ -z "${SSH_AUTH_SOCK}" ] || return 0
break
done
(( ${+commands[ssh-agent]} )) || return 127
if [ -z "${SSH_AUTH_SOCK}" ] ; then
local sock_dir
if [ "${XDG_RUNTIME_DIR}" = "${TMPDIR}" ] ; then
sock_dir="${ZSHU[d_zdot]}/.cache/ssh"
else
sock_dir="${XDG_RUNTIME_DIR}/ssh"
fi
mkdir -p "${sock_dir}"
SSH_AUTH_SOCK="${sock_dir}/ssh-agent.sock"
fi
{
eval "$(ssh-agent -s -k -a "${SSH_AUTH_SOCK}")"
} >/dev/null
}

View File

@ -5,8 +5,9 @@ z-orig-term() {
local i x
for i ( ${ZSHU_PARENTS_PID} ) ; do
[ -r "/proc/$i/environ" ] || continue
x=$(sed -zEn '/^TERM=(.+)$/{s//\1/;p;}' "/proc/$i/environ" 2>/dev/null | tr -d '\0')
i="${ZSHU[procfs]}/$i/environ"
[ -r "$i" ] || continue
x=$(sed -zEn '/^TERM=(.+)$/{s//\1/;p;}' "$i" 2>/dev/null | tr -d '\0')
[ -n "$x" ] || continue
a+=( "$x" )
done