1
0

zsh: update

This commit is contained in:
Konstantin Demin 2024-01-27 00:10:58 +03:00
parent d5209414e9
commit 9d1de60648
Signed by: krd
GPG Key ID: 1F33CB0BA4731BC6
21 changed files with 258 additions and 81 deletions

View File

@ -5,6 +5,7 @@
!/.config/dotfiles/gen-gitignore.sh
!/.config/dotfiles/gitignore
!/.config/dotfiles/install.sh
!/.config/dotfiles/scripts/.keep
!/.config/htop/htoprc.example
!/.config/zsh/_.zsh
!/.config/zsh/alias.zsh
@ -20,6 +21,8 @@
!/.config/zsh/alias/kconfig.zsh
!/.config/zsh/alias/ls.zsh
!/.config/zsh/alias/podman.zsh
!/.config/zsh/alias/quilt.zsh
!/.config/zsh/alias/sbuild.zsh
!/.config/zsh/alias/sudo.zsh
!/.config/zsh/alias/telnet.zsh
!/.config/zsh/completion/.keep

View File

View File

@ -12,9 +12,10 @@ ZSHU[d_conf]="${ZDOTDIR}/.config/zsh"
ZSHU[d_var]="${ZSHU[d_conf]}/var"
ZSHU[d_bin]="${ZDOTDIR}/.config/dotfiles/bin/"
ZSHU[d_bin]="${ZDOTDIR}/.config/dotfiles/bin"
ZSHU[d_scripts]="${ZDOTDIR}/.config/dotfiles/scripts"
for i ( d_zdot d_cache d_conf d_bin d_var ) ; do
for i ( d_zdot d_cache d_conf d_bin d_scripts d_var ) ; do
d=${ZSHU[$i]}
[ -d "$d" ] || mkdir -p "$d"
done ; unset i d
@ -36,12 +37,12 @@ umask 0022
zshu_parts=( env opt lib rc alias local )
for n ( $zshu_parts ) ; do
for n ( ${zshu_parts} ) ; do
f="${ZSHU[d_conf]}/$n.zsh"
[ -s "$f" ] && source "$f"
done ; unset n f
for n ( $zshu_parts ) ; do
for n ( ${zshu_parts} ) ; do
d="${ZSHU[d_conf]}/$n"
[ -d "$d" ] || continue
for i ( $d/*.zsh(N.r) ) ; do
@ -53,7 +54,7 @@ unset zshu_parts
ZSHU[t_end]=${(%):-%D{%s.%6.}}
ZSHU[t_load]=$(( ZSHU[t_end] - ZSHU[t_begin] ))
ZSHU[t_load]=$[ ZSHU[t_end] - ZSHU[t_begin] ]
ZSHU[t_load]=${ZSHU[t_load]:0:6}
unset 'ZSHU[t_begin]' 'ZSHU[t_end]'

View File

@ -10,14 +10,16 @@ git-dir-usage() {
else
d=$(__z_git rev-parse --path-format=absolute --git-dir)
fi
case "$d" in
*/* ) p=${d%/*} ; d=${d##*/} ;;
*/* ) p=${d%/*} ; d=${d:t} ;;
esac
## ${p:+ env -C "$p" } du -cd2 "$d"
## ${p:+ env -C "$p" } du -d2 "$d"
if [ -n "$p" ] ; then
env -C "$p" du -cd2 "$d"
env -C "$p" du -d2 "$d"
else
du -cd2 "$d"
du -d2 "$d"
fi | grep -Ev '^[0-9]\s' | sort -Vk2
}

View File

@ -1,14 +1,14 @@
#!/bin/zsh
gpg-warmup() {
local t r
(( ${+commands[gpg]} )) || return 1
local t r
t=$(mktemp)
command gpg -abs "$t"
r=$?
command rm -f "$t" "$t.asc"
rm -f "$t" "$t.asc"
return "$r"
}

View File

@ -9,11 +9,12 @@ z-alt-grep() {
n=${#a}
[ -z "$1" ] && n=0
case "$n" in
0) ;;
*) z-alt-set-static \
"grep|-q -e ' ' ${ZSHU[d_conf]}/_.zsh" \
"$1" \
"GREP_OPTIONS='' command" \
0 ) ;;
* )
z-alt-set-static \
"grep|-q -e ' ' ${ZSHU[d_conf]}/_.zsh" \
"$1" \
"GREP_OPTIONS='' command" \
;;
esac
}
@ -25,5 +26,6 @@ z-alt-grep "grep ${GREP_GNU}|grep"
unfunction z-alt-grep
unset GREP_GNU
alias grep='grep '
alias egrep='grep -E '
alias fgrep='grep -F '

View File

@ -1,16 +1,24 @@
#!/bin/zsh
idle() {
[ -n "${1:?}" ] || return 1
local f
f=$(type "$1")
case "$f" in
"$1 is /"*) z-idle-ext "$@" ;;
*) z-idle-int "$@" ;;
"$1 is /"* )
z-idle-ext "$@"
;;
* )
z-idle-int "$@"
;;
esac
}
z-idle-ext() {
[ -n "${1:?}" ] || return 1
local -a s
s+=( $(z-alt-find 'nice -n +40') )
@ -20,6 +28,8 @@ z-idle-ext() {
}
z-idle-int() {
[ -n "${1:?}" ] || return 1
## execute in subshell
(
{

View File

@ -1,3 +1,3 @@
#!/bin/zsh
alias k=kubectl
alias k='kubectl '

View File

@ -1,17 +1,25 @@
#!/bin/zsh
kconf-set() {
local n v
[ -n "${1:?}" ] || return 1
n=$1 v=$2 ; shift 2
grep -ElZ "^((CONFIG_)?$n=|# (CONFIG_)?$n is not set)" "$@" \
local n=$1 v=$2
shift 2
[ $# -gt 0 ] || return 2
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() {
local n
[ -n "${1:?}" ] || return 1
n=$1 ; shift
grep -ElZ "^(CONFIG_)?$n=" "$@" \
local n=$1
shift
[ $# -gt 0 ] || return 2
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 @@ if [ -z "${LS_COLORS}" ] ; then
fi
case "${ZSHU[os_family]}" in
bsd|darwin) export LSCOLORS="Gxfxcxdxbxegedabagacad" ;;
bsd | darwin ) export LSCOLORS="Gxfxcxdxbxegedabagacad" ;;
esac
z-alt-ls() {
@ -17,11 +17,12 @@ z-alt-ls() {
n=${#a}
[ -z "$1" ] && n=0
case "$n" in
0) ;;
*) z-alt-set-static \
'ls|-d .' \
"$1" \
"LS_OPTIONS='' command"
0 ) ;;
* )
z-alt-set-static \
'ls|-d .' \
"$1" \
"LS_OPTIONS='' command"
;;
esac
}
@ -29,12 +30,12 @@ z-alt-ls() {
LS_GNU='--color=tty --group-directories-first'
case "${ZSHU[os_type]}" in
linux*) alt="ls ${LS_GNU}|ls" ;;
netbsd*) alt="gls ${LS_GNU}|ls" ;;
openbsd*) alt="gls ${LS_GNU}|colorls -G|ls" ;;
freebsd*) alt="gls ${LS_GNU}|ls -G|ls" ;;
darwin*) alt="gls ${LS_GNU}|ls -G|ls" ;;
*) alt="ls ${LS_GNU}|ls" ;;
linux* ) alt="ls ${LS_GNU}|ls" ;;
netbsd* ) alt="gls ${LS_GNU}|ls" ;;
openbsd* ) alt="gls ${LS_GNU}|colorls -G|ls" ;;
freebsd* ) alt="gls ${LS_GNU}|ls -G|ls" ;;
darwin* ) alt="gls ${LS_GNU}|ls -G|ls" ;;
* ) alt="ls ${LS_GNU}|ls" ;;
esac
z-alt-ls "${alt}"
@ -44,13 +45,13 @@ unset alt LS_GNU
[ -n "${LS_COLORS}" ] && zstyle ':completion:*' list-colors "${(s.:.)LS_COLORS}"
case "${ZSHU[os_family]}" in
linux) alias l='ls -lhF ' ;;
bsd) alias l='ls -lhIF ' ;;
linux ) alias l='ls -lhF ' ;;
bsd ) alias l='ls -lhIF ' ;;
esac
alias ll='ls -lAF '
case "${ZSHU[os_family]}" in
linux) alias lll='ls -lAn --full-time ' ;;
bsd) alias lll='ls -lAnT ' ;;
linux ) alias lll='ls -lAn --full-time ' ;;
bsd ) alias lll='ls -lAnT ' ;;
esac

View File

@ -0,0 +1,79 @@
#!/bin/zsh
quilt-series-strip-comments() {
sed -E '/^[[:space:]]*(#|$)/d' "$@"
}
quilt-series-auto() {
[ -n "${1:?}" ] || return 1
find "$1/" -follow -type f -printf '%P\0' \
| sed -zEn '/\.(diff|patch)$/p' \
| sort -zuV | xargs -0r -n1
}
krd-quilt() {
[ -n "${1:?}" ] || return 1
(( $+commands[quilt] )) || return 2
local patchdir series tmp_series
if [ -d "$1" ] ; then
patchdir="$1/debian/patches"
if [ -d "${patchdir}" ] ; then
[ -f "${patchdir}/series" ] || return 3
else
patchdir="$1"
fi
series="${patchdir}/series"
if ! [ -f "${series}" ] ; then
tmp_series=1
series=$(mktemp)
quilt-series-auto "${patchdir}" > "${series}"
fi
elif [ -f "$1" ] ; then
[ -s "$1" ] || return 3
series="$1"
patchdir=${series:h}
else
return 3
fi
local r
(
z-quilt-default-env
set -a
QUILT_SERIES="${series}"
QUILT_PATCHES="${patchdir}"
set +a
command quilt pop -a ; echo
r=0
while read -r i ; do
[ -n "$i" ] || continue
k="${patchdir}/$i"
command quilt --fuzz=0 push "$k"
r=$? ; [ $r -eq 0 ] || exit $r
command quilt refresh "$k"
r=$? ; [ $r -eq 0 ] || exit $r
sed -E -i \
-e 's#^(-{3} )[^/][^/]*/(.*)$#\1a/\2#;' \
-e 's#^(\+{3} )[^/][^/]*/(.*)$#\1b/\2#' \
"$k"
rm -f "$k"'~'
done <<< $(quilt-series-strip-comments "${series}")
exit $r
)
r=$?
[ -z "${tmp_series}" ] || rm -f "${series}"
return $r
}

View File

@ -0,0 +1,67 @@
#!/bin/zsh
krd-debsrc() {
[ -n "${1:?}" ] || return 1
local dstdir
case "$1" in
*/* ) dstdir="$1/src" ;;
* ) dstdir="/tmp/$1/src" ;;
esac
rm -rf "${dstdir}"
deb-src-export "${dstdir}"
}
krd-sbuild() {
[ -n "${1:?}" ] || return 1
[ -n "${2:?}" ] || return 1
(( $+commands[sbuild] )) || return 2
(( $+commands[xz] )) || return 2
local topdir
case "$1" in
*/* ) topdir="$1" ;;
* ) topdir="/tmp/$1" ;;
esac
[ -d "${topdir}" ] || return 3
local srcdir="${topdir}/src"
[ -d "${srcdir}" ] || return 3
arch="$2"
## done with args
shift 2
local -a sbuild_env sbuild_args
local i
for i ; do
## naive splitting args and env
case "$i" in
*=* ) sbuild_env+=( $i ) ;;
*) sbuild_args+=( $i ) ;;
esac
done
(
for i ( ${sbuild_env} ) ; do
export "$i"
done
z-set-tmpdir /tmp
builddir="${topdir}/${arch}"
mkdir -p "${topdir}/all" "${builddir}" "${builddir}-debug"
cd "${builddir}"
for i ( "${srcdir}"/*.dsc(N.r) ) ; do
idle sbuild --arch-all --arch-any --arch=${arch} ${sbuild_args[@]} "$i"
find -name '*.build' -type l -exec rm -f {} +
find -name '*.build' -type f -exec xz -9vv {} +
done
find -name '*dbgsym*.deb' -type f -exec mv -nvt "../${arch}-debug" {} +
find -name '*_all.deb' -type f -exec mv -nvt '../all' {} +
)
}

View File

@ -1,6 +1,6 @@
#!/bin/zsh
case "${ZSHU[os_type]}" in
linux-gnu) alias tl='telnet -K ' ;;
*bsd*) alias tl='telnet -K -N -y ' ;;
linux-gnu ) alias tl='telnet -K ' ;;
*bsd* ) alias tl='telnet -K -N -y ' ;;
esac

View File

@ -14,7 +14,7 @@ function {
## process in-home part
t=( ${(@)p:#${HOME}/*} )
npath+=( "${ZSHU[d_bin]}" "${HOME}/bin" )
npath+=( "${ZSHU[d_scripts]}" "${ZSHU[d_bin]}" "${HOME}/bin" )
npath+=( ${(@)p:|t} )
p=( $t )
@ -65,16 +65,16 @@ ZSHU[uname]=${ZSHU[uname]:l}
ZSHU[mach]=$(uname -m 2>/dev/null)
ZSHU[mach]=${ZSHU[mach]:l}
case "${ZSHU[mach]}" in
amd64) ZSHU[mach]=x86_64 ;;
arm64) ZSHU[mach]=aarch64 ;;
armv*) ZSHU[mach]=arm ;;
amd64 ) ZSHU[mach]=x86_64 ;;
arm64 ) ZSHU[mach]=aarch64 ;;
armv* ) ZSHU[mach]=arm ;;
esac
ZSHU[os_type]=${OSTYPE:l}
ZSHU[os_family]=${ZSHU[uname]:l}
case "${ZSHU[os_family]}" in
*bsd) ZSHU[os_family]=bsd ;;
*bsd ) ZSHU[os_family]=bsd ;;
esac
ZSHU[host_name]=${(%):-%m}

View File

@ -1,11 +1,15 @@
#!/bin/zsh
QUILT_PATCHES="debian/patches"
QUILT_NO_DIFF_INDEX=1
QUILT_NO_DIFF_TIMESTAMPS=1
QUILT_PATCH_OPTS="--reject-format=unified"
QUILT_DIFF_ARGS="-p ab --no-timestamps --no-index --color=auto"
QUILT_REFRESH_ARGS="-p ab --no-timestamps --no-index"
QUILT_COLORS="diff_hdr=1;32:diff_add=1;34:diff_rem=1;31:diff_hunk=1;33:diff_ctx=35:diff_cctx=33"
z-quilt-default-env() {
set -a
QUILT_PATCHES='debian/patches'
QUILT_NO_DIFF_INDEX=1
QUILT_NO_DIFF_TIMESTAMPS=1
QUILT_PATCH_OPTS='--reject-format=unified'
QUILT_DIFF_ARGS='-pab --no-timestamps --no-index --color=auto'
QUILT_REFRESH_ARGS='-pab --no-timestamps --no-index'
QUILT_COLORS='diff_hdr=1;32:diff_add=1;34:diff_rem=1;31:diff_hunk=1;33:diff_ctx=35:diff_cctx=33'
set +a
}
typeset -x -m 'QUILT*'
z-quilt-default-env

View File

@ -5,7 +5,7 @@ z-time() {
a=${EPOCHREALTIME}
"$@" ; r=$?
a=$(( EPOCHREALTIME - a ))
a=$[ EPOCHREALTIME - a ]
a=$(z-ts-to-human "$a" 6)
echo >&2
echo "time took: $a" >&2
@ -16,7 +16,7 @@ z-time() {
if autoload -Uz add-zsh-hook ; then
typeset -gA ZSHU_PS
ZSHU_PS[cmd_threshold]=1
ZSHU_PS[cmd_threshold]=3
__z_cmdtime_measure() {
local t x
@ -26,14 +26,14 @@ __z_cmdtime_measure() {
unset 'ZSHU[cmd_dt]' 'ZSHU_PS[elapsed]'
(( ${+ZSHU[cmd_ts]} )) || return
t=$(( x - ${ZSHU[cmd_ts]} ))
t=$[ x - ZSHU[cmd_ts] ]
ZSHU[cmd_ts]=$x
x=${ZSHU_PS[cmd_threshold]}
x=$(( x + 0 )) || x=0
x=$[ x + 0 ] || x=0
[ "$x" = 0 ] && return
x=$(( t - x ))
x=$[ t - x ]
[ "${x:0:1}" = '-' ] && return
t=$(z-ts-to-human "$t")

View File

@ -9,7 +9,7 @@ fpath=( "${ZSHU[d_cache]}/completion" $fpath )
__z_compdump_print() { printf '#zshu %s %s\n' "$1" "${(P)1}" ; }
__z_compdump_invalidate() {
command rm -f "${ZSHU[f_compdump]}"
rm -f "${ZSHU[f_compdump]}"
find "${ZSHU[d_compcache]}/" -xdev -type f '!' -name '.keep' -delete
ZSHU[compdump_refresh]=1
}
@ -99,5 +99,5 @@ z-comp-invalidate() {
f="${ZSHU[d_cache]}/completion/_$1"
[ -f "$f" ] || return 2
command rm -f "$f" || return 3
rm -f "$f" || return 3
}

View File

@ -18,7 +18,7 @@ function {
for i ( ${ZSHU_PARENTS_PID} ) ; do
c=$(ps -o comm= -p $i 2>/dev/null) || :
[ -n "$c" ] || continue
ZSHU_PARENTS_NAME+=( "${c##*/}" )
ZSHU_PARENTS_NAME+=( "${c:t}" )
done
typeset -r ZSHU_PARENTS_PID

View File

@ -4,23 +4,23 @@ z-ts-to-human() {
local t s n d h m f x
t=$1
t=$(( float(t) ))
s=$(( int(t) ))
n=$(( int((t - s) * (10**9)) ))
t=$[ float(t) ]
s=$[ int(t) ]
n=$[ int((t - s) * (10**9)) ]
t=$s
d=0 h=0 m=0
if [ $t -ge 86400 ] ; then
d=$(( t / 86400 ))
t=$(( t % 86400 ))
d=$[ t / 86400 ]
t=$[ t % 86400 ]
fi
if [ $t -ge 3600 ] ; then
h=$(( t / 3600 ))
t=$(( t % 3600 ))
h=$[ t / 3600 ]
t=$[ t % 3600 ]
fi
if [ $t -ge 60 ] ; then
m=$(( t / 60 ))
t=$(( t % 60 ))
m=$[ t / 60 ]
t=$[ t % 60 ]
fi
## strftime does desired rounding for $n/(10**9) internally
@ -28,8 +28,8 @@ z-ts-to-human() {
## keep math in sync with format above
x=3
case "$2" in
0) x=7 ;;
[1-6]) x=$(( 6 - $2 )) ;;
0 ) x=7 ;;
[1-6] ) x=$[ 6 - $2 ] ;;
esac
[ $x -gt 0 ] && f="${f:0:-$x}s"

View File

@ -7,14 +7,14 @@ z-title-tab() {
emulate -L zsh
case "${TERM}" in
cygwin|xterm*|putty*|rxvt*|konsole*|ansi|mlterm*|alacritty|st*)
cygwin | xterm* | putty* | rxvt* | konsole* | ansi | mlterm* | alacritty | st* )
print -Pn "\e]1;${1:q}\a"
;;
screen*|tmux*)
screen* | tmux* )
## hardstatus
print -Pn "\ek${1:q}\e\\"
;;
*)
* )
z-ti-test fsl tsl || return
echoti tsl
@ -28,7 +28,7 @@ z-title-window() {
emulate -L zsh
case "${TERM}" in
cygwin|xterm*|putty*|rxvt*|konsole*|ansi|mlterm*|alacritty|st*)
cygwin | xterm* | putty* | rxvt* | konsole* | ansi | mlterm* | alacritty | st* )
print -Pn "\e]2;${1:q}\a"
;;
esac

View File

@ -85,7 +85,7 @@ z-bind () {
[ ${#keys} -eq 0 ] && return 1
case "${widget}" in
/*)
/* )
widget=${widget:1}
emulate zsh -c "autoload -RUz ${widget}"
zle -N "${widget}"