zsh: update
This commit is contained in:
parent
d5209414e9
commit
9d1de60648
@ -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
|
||||
|
0
.config/dotfiles/scripts/.keep
Normal file
0
.config/dotfiles/scripts/.keep
Normal 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]'
|
||||
|
@ -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
|
||||
}
|
||||
|
||||
|
@ -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"
|
||||
}
|
||||
|
@ -10,7 +10,8 @@ z-alt-grep() {
|
||||
[ -z "$1" ] && n=0
|
||||
case "$n" in
|
||||
0 ) ;;
|
||||
*) z-alt-set-static \
|
||||
* )
|
||||
z-alt-set-static \
|
||||
"grep|-q -e ' ' ${ZSHU[d_conf]}/_.zsh" \
|
||||
"$1" \
|
||||
"GREP_OPTIONS='' command" \
|
||||
@ -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 '
|
||||
|
@ -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
|
||||
(
|
||||
{
|
||||
|
@ -1,3 +1,3 @@
|
||||
#!/bin/zsh
|
||||
|
||||
alias k=kubectl
|
||||
alias k='kubectl '
|
||||
|
@ -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/"
|
||||
}
|
||||
|
@ -18,7 +18,8 @@ z-alt-ls() {
|
||||
[ -z "$1" ] && n=0
|
||||
case "$n" in
|
||||
0 ) ;;
|
||||
*) z-alt-set-static \
|
||||
* )
|
||||
z-alt-set-static \
|
||||
'ls|-d .' \
|
||||
"$1" \
|
||||
"LS_OPTIONS='' command"
|
||||
|
79
.config/zsh/alias/quilt.zsh
Normal file
79
.config/zsh/alias/quilt.zsh
Normal 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
|
||||
}
|
67
.config/zsh/alias/sbuild.zsh
Normal file
67
.config/zsh/alias/sbuild.zsh
Normal 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' {} +
|
||||
)
|
||||
}
|
@ -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 )
|
||||
|
||||
|
16
.config/zsh/env/quilt.zsh
vendored
16
.config/zsh/env/quilt.zsh
vendored
@ -1,11 +1,15 @@
|
||||
#!/bin/zsh
|
||||
|
||||
QUILT_PATCHES="debian/patches"
|
||||
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="-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"
|
||||
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
|
||||
|
@ -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")
|
||||
|
@ -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
|
||||
}
|
||||
|
@ -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
|
||||
|
@ -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
|
||||
@ -29,7 +29,7 @@ z-ts-to-human() {
|
||||
x=3
|
||||
case "$2" in
|
||||
0 ) x=7 ;;
|
||||
[1-6]) x=$(( 6 - $2 )) ;;
|
||||
[1-6] ) x=$[ 6 - $2 ] ;;
|
||||
esac
|
||||
[ $x -gt 0 ] && f="${f:0:-$x}s"
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user