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/gen-gitignore.sh
!/.config/dotfiles/gitignore !/.config/dotfiles/gitignore
!/.config/dotfiles/install.sh !/.config/dotfiles/install.sh
!/.config/dotfiles/scripts/.keep
!/.config/htop/htoprc.example !/.config/htop/htoprc.example
!/.config/zsh/_.zsh !/.config/zsh/_.zsh
!/.config/zsh/alias.zsh !/.config/zsh/alias.zsh
@ -20,6 +21,8 @@
!/.config/zsh/alias/kconfig.zsh !/.config/zsh/alias/kconfig.zsh
!/.config/zsh/alias/ls.zsh !/.config/zsh/alias/ls.zsh
!/.config/zsh/alias/podman.zsh !/.config/zsh/alias/podman.zsh
!/.config/zsh/alias/quilt.zsh
!/.config/zsh/alias/sbuild.zsh
!/.config/zsh/alias/sudo.zsh !/.config/zsh/alias/sudo.zsh
!/.config/zsh/alias/telnet.zsh !/.config/zsh/alias/telnet.zsh
!/.config/zsh/completion/.keep !/.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_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=${ZSHU[$i]}
[ -d "$d" ] || mkdir -p "$d" [ -d "$d" ] || mkdir -p "$d"
done ; unset i d done ; unset i d
@ -36,12 +37,12 @@ umask 0022
zshu_parts=( env opt lib rc alias local ) zshu_parts=( env opt lib rc alias local )
for n ( $zshu_parts ) ; do for n ( ${zshu_parts} ) ; do
f="${ZSHU[d_conf]}/$n.zsh" f="${ZSHU[d_conf]}/$n.zsh"
[ -s "$f" ] && source "$f" [ -s "$f" ] && source "$f"
done ; unset n f done ; unset n f
for n ( $zshu_parts ) ; do for n ( ${zshu_parts} ) ; do
d="${ZSHU[d_conf]}/$n" d="${ZSHU[d_conf]}/$n"
[ -d "$d" ] || continue [ -d "$d" ] || continue
for i ( $d/*.zsh(N.r) ) ; do for i ( $d/*.zsh(N.r) ) ; do
@ -53,7 +54,7 @@ unset zshu_parts
ZSHU[t_end]=${(%):-%D{%s.%6.}} 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} ZSHU[t_load]=${ZSHU[t_load]:0:6}
unset 'ZSHU[t_begin]' 'ZSHU[t_end]' unset 'ZSHU[t_begin]' 'ZSHU[t_end]'

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

@ -18,7 +18,8 @@ z-alt-ls() {
[ -z "$1" ] && n=0 [ -z "$1" ] && n=0
case "$n" in case "$n" in
0 ) ;; 0 ) ;;
*) z-alt-set-static \ * )
z-alt-set-static \
'ls|-d .' \ 'ls|-d .' \
"$1" \ "$1" \
"LS_OPTIONS='' command" "LS_OPTIONS='' command"

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

@ -14,7 +14,7 @@ function {
## process in-home part ## process in-home part
t=( ${(@)p:#${HOME}/*} ) t=( ${(@)p:#${HOME}/*} )
npath+=( "${ZSHU[d_bin]}" "${HOME}/bin" ) npath+=( "${ZSHU[d_scripts]}" "${ZSHU[d_bin]}" "${HOME}/bin" )
npath+=( ${(@)p:|t} ) npath+=( ${(@)p:|t} )
p=( $t ) p=( $t )

View File

@ -1,11 +1,15 @@
#!/bin/zsh #!/bin/zsh
QUILT_PATCHES="debian/patches" z-quilt-default-env() {
set -a
QUILT_PATCHES='debian/patches'
QUILT_NO_DIFF_INDEX=1 QUILT_NO_DIFF_INDEX=1
QUILT_NO_DIFF_TIMESTAMPS=1 QUILT_NO_DIFF_TIMESTAMPS=1
QUILT_PATCH_OPTS="--reject-format=unified" QUILT_PATCH_OPTS='--reject-format=unified'
QUILT_DIFF_ARGS="-p ab --no-timestamps --no-index --color=auto" QUILT_DIFF_ARGS='-pab --no-timestamps --no-index --color=auto'
QUILT_REFRESH_ARGS="-p ab --no-timestamps --no-index" 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" 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} a=${EPOCHREALTIME}
"$@" ; r=$? "$@" ; r=$?
a=$(( EPOCHREALTIME - a )) a=$[ EPOCHREALTIME - a ]
a=$(z-ts-to-human "$a" 6) a=$(z-ts-to-human "$a" 6)
echo >&2 echo >&2
echo "time took: $a" >&2 echo "time took: $a" >&2
@ -16,7 +16,7 @@ z-time() {
if autoload -Uz add-zsh-hook ; then if autoload -Uz add-zsh-hook ; then
typeset -gA ZSHU_PS typeset -gA ZSHU_PS
ZSHU_PS[cmd_threshold]=1 ZSHU_PS[cmd_threshold]=3
__z_cmdtime_measure() { __z_cmdtime_measure() {
local t x local t x
@ -26,14 +26,14 @@ __z_cmdtime_measure() {
unset 'ZSHU[cmd_dt]' 'ZSHU_PS[elapsed]' unset 'ZSHU[cmd_dt]' 'ZSHU_PS[elapsed]'
(( ${+ZSHU[cmd_ts]} )) || return (( ${+ZSHU[cmd_ts]} )) || return
t=$(( x - ${ZSHU[cmd_ts]} )) t=$[ x - ZSHU[cmd_ts] ]
ZSHU[cmd_ts]=$x ZSHU[cmd_ts]=$x
x=${ZSHU_PS[cmd_threshold]} x=${ZSHU_PS[cmd_threshold]}
x=$(( x + 0 )) || x=0 x=$[ x + 0 ] || x=0
[ "$x" = 0 ] && return [ "$x" = 0 ] && return
x=$(( t - x )) x=$[ t - x ]
[ "${x:0:1}" = '-' ] && return [ "${x:0:1}" = '-' ] && return
t=$(z-ts-to-human "$t") 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_print() { printf '#zshu %s %s\n' "$1" "${(P)1}" ; }
__z_compdump_invalidate() { __z_compdump_invalidate() {
command rm -f "${ZSHU[f_compdump]}" rm -f "${ZSHU[f_compdump]}"
find "${ZSHU[d_compcache]}/" -xdev -type f '!' -name '.keep' -delete find "${ZSHU[d_compcache]}/" -xdev -type f '!' -name '.keep' -delete
ZSHU[compdump_refresh]=1 ZSHU[compdump_refresh]=1
} }
@ -99,5 +99,5 @@ z-comp-invalidate() {
f="${ZSHU[d_cache]}/completion/_$1" f="${ZSHU[d_cache]}/completion/_$1"
[ -f "$f" ] || return 2 [ -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 for i ( ${ZSHU_PARENTS_PID} ) ; do
c=$(ps -o comm= -p $i 2>/dev/null) || : c=$(ps -o comm= -p $i 2>/dev/null) || :
[ -n "$c" ] || continue [ -n "$c" ] || continue
ZSHU_PARENTS_NAME+=( "${c##*/}" ) ZSHU_PARENTS_NAME+=( "${c:t}" )
done done
typeset -r ZSHU_PARENTS_PID typeset -r ZSHU_PARENTS_PID

View File

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