From e3ff1bcb695b5106f6a46efaebe91e1a0b2eb318 Mon Sep 17 00:00:00 2001 From: Konstantin Demin Date: Fri, 5 Jul 2024 13:18:16 +0300 Subject: [PATCH] zsh: update --- .config/dotfiles/gitignore | 1 + .config/dotfiles/woodpecker.yml | 2 +- .config/zsh/alias/containers.zsh | 84 ++++++++++++++++++++++--------- .config/zsh/alias/directories.zsh | 2 +- .config/zsh/alias/git.zsh | 2 +- .config/zsh/alias/quilt.zsh | 55 ++++++++++++++++---- .config/zsh/alias/sudo.zsh | 2 +- .config/zsh/env/aux.zsh | 2 +- .config/zsh/env/containers.zsh | 5 ++ .config/zsh/env/gopath.zsh | 1 - .config/zsh/env/sed.zsh | 3 ++ .config/zsh/lib/completion.zsh | 2 +- .config/zsh/opt/chase.zsh | 6 +-- .config/zsh/rc/completion.zsh | 1 + 14 files changed, 124 insertions(+), 44 deletions(-) create mode 100644 .config/zsh/env/sed.zsh diff --git a/.config/dotfiles/gitignore b/.config/dotfiles/gitignore index faed3b0..5cd5e13 100644 --- a/.config/dotfiles/gitignore +++ b/.config/dotfiles/gitignore @@ -44,6 +44,7 @@ !/.config/zsh/env/ld.so.zsh !/.config/zsh/env/pager.zsh !/.config/zsh/env/quilt.zsh +!/.config/zsh/env/sed.zsh !/.config/zsh/env/xdg.zsh !/.config/zsh/lib.zsh !/.config/zsh/lib/alternatives.zsh diff --git a/.config/dotfiles/woodpecker.yml b/.config/dotfiles/woodpecker.yml index 11931fe..5cd6a31 100644 --- a/.config/dotfiles/woodpecker.yml +++ b/.config/dotfiles/woodpecker.yml @@ -20,7 +20,7 @@ steps: } if find_fast ./ -type f -name '*.zwc' ; then echo 'found *.zwc' >&2 - find ./ -type f -name '*.zwc' + find ./ -type f -name '*.zwc' | sort -V exit 1 fi - | diff --git a/.config/zsh/alias/containers.zsh b/.config/zsh/alias/containers.zsh index d1226a1..ebe2e0c 100644 --- a/.config/zsh/alias/containers.zsh +++ b/.config/zsh/alias/containers.zsh @@ -1,21 +1,68 @@ #!/bin/zsh -alias bud='buildah bud --isolation chroot --network host --format docker -f ' - -alias pod-run='podman run -e "TERM=${TERM:-linux}" --rm -it ' -alias pod-images='podman images --format "table {{.ID}} {{.Repository}}:{{.Tag}} {{.Size}} {{.Created}} |{{.CreatedAt}}" ' -alias pod-inspect='podman inspect ' -alias pod-logs='podman logs ' - typeset -Uga ZSHU_CNTR_SHELLS=( /bin/bash /bin/sh /bin/ash ) typeset -ga ZSHU_CNTR_FALLBACK_SHELL=( /busybox/busybox sh ) +alias bud='buildah bud --network=host -f ' + +function { + local i + for i ( run images ps inspect logs ) ; do + alias "pod-$i"="podman $i " + done +} + z-pod() { command podman "$@" ; } +alias podman='z-podman ' +z-podman() { + case "${1:-}" in + run ) shift ; z-pod-run "$@" ;; + images ) shift ; z-pod-images "$@" ;; + ps ) shift ; z-pod-ps "$@" ;; + * ) z-pod "$@" ;; + esac +} + z-pod-run() { z-pod run -e "TERM=${TERM:-linux}" --rm -it "$@" } +z-pod-images() { + local have_flags=0 + case "$1" in + -* ) have_flags=1 ;; + esac + if [ ${have_flags} = 1 ] ; then + z-pod images "$@" + else + z-pod images --format 'table {{.ID}} {{.Repository}}:{{.Tag}} {{.Size}} {{.Created}} |{{.CreatedAt}}' "$@" + fi +} + +z-pod-ps() { + local have_flags=0 + case "$1" in + -* ) have_flags=1 ;; + esac + if [ ${have_flags} = 1 ] ; then + z-pod ps "$@" + else + z-pod ps -a --sort names --format 'table {{.ID}} {{.Names}} {{.Image}} {{.CreatedHuman}} {{.Status}}' "$@" + fi +} + +pod-images-grep() { + z-pod-images \ + | { + if [ -z "$1" ] ; then + head + else + sed -En "1{p;D};\\${ZSHU_XSED}$1${ZSHU_XSED}p" + fi + } +} + ## NB: naive. rewrite! pod-run-sh() { local -a cntr_opts=( --network=host --entrypoint='[]' --user=0:0 ) @@ -39,40 +86,30 @@ pod-run-sh() { z-pod-run ${cntr_opts[@]} "$@" ${shell[@]} } -pod-ps() { - [ $# -ne 0 ] || set -- -a --format 'table {{.ID}} {{.Names}} {{.Image}} {{.CreatedHuman}} {{.Status}}' - command podman ps "$@" -} - +## NB: naive. rewrite! sko-inspect() { local i i="${1:?}" ; shift command skopeo inspect "$@" "docker://$i" } +## NB: naive. rewrite! sko-list-tags() { local i i="${1:?}" ; shift command skopeo list-tags "$@" "docker://$i" } +## NB: naive. rewrite! pod-dive() { local i i="${1:?}" ; shift command dive "$@" "podman://$i" } -jq-visual() { - command jq -C | less -} - -jq-config() { - command jq '.[].Config' -} - -jq-tags() { - command jq -r '.Tags[]' -} +jq-visual() { jq -C | "${PAGER:-cat}" ; } +jq-config() { jq '.[].Config' ; } +jq-tags() { jq -r '.Tags[]' ; } alias dkr='docker ' alias dkr-run='dkr run -e "TERM=${TERM:-linux}" --rm -it ' @@ -110,6 +147,7 @@ dkr-run-sh() { z-dkr-run ${cntr_opts[@]} "$@" ${shell[@]} } +## NB: naive. rewrite! dkr-dive() { local i i="${1:?}" ; shift diff --git a/.config/zsh/alias/directories.zsh b/.config/zsh/alias/directories.zsh index 830b7b3..f73c37a 100644 --- a/.config/zsh/alias/directories.zsh +++ b/.config/zsh/alias/directories.zsh @@ -28,4 +28,4 @@ gd() { cd "$1" ;; esac -} \ No newline at end of file +} diff --git a/.config/zsh/alias/git.zsh b/.config/zsh/alias/git.zsh index 1e36d8d..0205ea1 100644 --- a/.config/zsh/alias/git.zsh +++ b/.config/zsh/alias/git.zsh @@ -51,4 +51,4 @@ git-archive-ref() { topdir=${topdir:h} git archive --format=tar -o "${topdir}/${out}" --prefix="${name}-${ver}-git.${c_hash}/" "${gitref}" || return $? echo "archived to ${out} in ${topdir}/" >&2 -} \ No newline at end of file +} diff --git a/.config/zsh/alias/quilt.zsh b/.config/zsh/alias/quilt.zsh index 5bb79de..d860b2b 100644 --- a/.config/zsh/alias/quilt.zsh +++ b/.config/zsh/alias/quilt.zsh @@ -1,20 +1,45 @@ #!/bin/zsh +z-quilt() { command quilt "$@" ; } + quilt-series-strip-comments() { sed -E '/^[[:space:]]*(#|$)/d' "$@" } quilt-series-auto() { [ -n "${1:?}" ] + [ -d "$1" ] || return 1 find "$1/" -follow -type f -printf '%P\0' \ | sed -zEn '/\.(diff|patch)$/p' \ - | sort -zuV | xargs -0r -n1 + | sort -zuV \ + | xargs -0r printf '%s\n' } krd-quilt() { (( $+commands[quilt] )) || return 127 + [ $# -gt 0 ] || return 1 + + local i + local -i n_opt=0 + local -i o_continue=0 + for i ; do + case "${i:?}" in + -c | --continue ) + o_continue=1 + ;; + -* ) + env printf 'unrecognized option: %q\n' "$1" + return 1 + ;; + * ) break ;; + esac + n_opt=$[n_opt+1] + done + + [ ${n_opt} -eq 0 ] || shift ${n_opt} + [ $# -gt 0 ] || return 1 [ -n "${1:?}" ] local patchdir series tmp_series @@ -29,17 +54,18 @@ krd-quilt() { series="${patchdir}/series" if ! [ -f "${series}" ] ; then - tmp_series=1 - series=$(mktemp) + mkdir -p "$1/.pc" || return 1 + series="$1/.pc/krd-quilt-series" + touch "${series}" || return 1 quilt-series-auto "${patchdir}" > "${series}" fi elif [ -f "$1" ] ; then - [ -s "$1" ] || return 2 + [ -s "$1" ] || return 1 series="$1" patchdir=${series:h} else - return 3 + return 1 fi local r @@ -50,16 +76,19 @@ krd-quilt() { QUILT_PATCHES="${patchdir}" set +a - command quilt pop -a ; echo + if [ ${o_continue} -eq 0 ] ; then + z-quilt pop -a + echo + fi r=0 while read -rs i ; do [ -n "$i" ] || continue k="${patchdir}/$i" - command quilt --fuzz=0 push "$k" + z-quilt --fuzz=0 push "$k" r=$? ; [ $r -eq 0 ] || exit $r - command quilt refresh "$k" + z-quilt refresh "$k" r=$? ; [ $r -eq 0 ] || exit $r sed -E -i \ @@ -68,12 +97,16 @@ krd-quilt() { "$k" rm -f "$k"'~' - done <<< $(quilt-series-strip-comments "${series}") + done <<< $( + if [ ${o_continue} -eq 1 ] ; then + z-quilt unapplied + else + quilt-series-strip-comments "${series}" + fi + ) exit $r ) r=$? - [ -z "${tmp_series}" ] || rm -f "${series}" - return $r } diff --git a/.config/zsh/alias/sudo.zsh b/.config/zsh/alias/sudo.zsh index 69a7517..7b4d1e8 100644 --- a/.config/zsh/alias/sudo.zsh +++ b/.config/zsh/alias/sudo.zsh @@ -7,4 +7,4 @@ function { fi alias sudo-i="$c" alias sudoi="$c" -} \ No newline at end of file +} diff --git a/.config/zsh/env/aux.zsh b/.config/zsh/env/aux.zsh index dd9fe1e..8ce8296 100644 --- a/.config/zsh/env/aux.zsh +++ b/.config/zsh/env/aux.zsh @@ -5,4 +5,4 @@ NO_AT_BRIDGE=1 QT_ACCESSIBILITY=0 MENUCONFIG_COLOR=blackbg -set +a \ No newline at end of file +set +a diff --git a/.config/zsh/env/containers.zsh b/.config/zsh/env/containers.zsh index 6a01394..ae22a28 100644 --- a/.config/zsh/env/containers.zsh +++ b/.config/zsh/env/containers.zsh @@ -1,5 +1,10 @@ #!/bin/zsh +BUILDAH_FORMAT=docker +BUILDAH_ISOLATION=chroot + +typeset -x -m 'BUILDAH_*' + BUILD_IMAGE_NETWORK=host BUILD_IMAGE_PUSH=0 diff --git a/.config/zsh/env/gopath.zsh b/.config/zsh/env/gopath.zsh index ed01fbb..184d801 100644 --- a/.config/zsh/env/gopath.zsh +++ b/.config/zsh/env/gopath.zsh @@ -16,7 +16,6 @@ z-gobin-fixup() { ## already in PATH? [ "${path[(I)${gobin}]}" = 0 ] || return 0 path=( "${gobin}" ${path} ) - hash -f } z-gobin-fixup diff --git a/.config/zsh/env/sed.zsh b/.config/zsh/env/sed.zsh new file mode 100644 index 0000000..60a0a10 --- /dev/null +++ b/.config/zsh/env/sed.zsh @@ -0,0 +1,3 @@ +#!/bin/zsh + +typeset -r ZSHU_XSED=$'\027' diff --git a/.config/zsh/lib/completion.zsh b/.config/zsh/lib/completion.zsh index 8be401a..0c9cdd5 100644 --- a/.config/zsh/lib/completion.zsh +++ b/.config/zsh/lib/completion.zsh @@ -142,4 +142,4 @@ z-comp-auto() { c=${f#__z_comp_ext__} __z_comp_external $c $f && unset -f "$f" done -} \ No newline at end of file +} diff --git a/.config/zsh/opt/chase.zsh b/.config/zsh/opt/chase.zsh index 142e7d3..e6805d0 100644 --- a/.config/zsh/opt/chase.zsh +++ b/.config/zsh/opt/chase.zsh @@ -1,5 +1,5 @@ #!/bin/zsh -chase() { setopt chase_dots chase_links ; } -nochase() { unsetopt chase_dots chase_links ; } -nochase +z-chase() { setopt chase_dots chase_links ; } +z-nochase() { unsetopt chase_dots chase_links ; } +z-nochase diff --git a/.config/zsh/rc/completion.zsh b/.config/zsh/rc/completion.zsh index 047172d..f1547ba 100644 --- a/.config/zsh/rc/completion.zsh +++ b/.config/zsh/rc/completion.zsh @@ -26,6 +26,7 @@ zstyle ':completion:*:kill:*' command 'ps -u ${USER} -o pid,%cpu,tty,cputime,cmd autoload -Uz +X compinit && \ compinit -i -C -d "${ZSHU[f_compdump]}" +unset 'ZSHU[compdump_bash]' if autoload -Uz +X bashcompinit ; then bashcompinit && ZSHU[compdump_bash]=1 fi