1
0

zsh: update

This commit is contained in:
Konstantin Demin 2024-02-18 02:32:08 +03:00
parent aea9334649
commit 9725317a4a
Signed by: krd
GPG Key ID: 1F33CB0BA4731BC6
8 changed files with 100 additions and 23 deletions

View File

@ -9,7 +9,7 @@
!/.config/htop/htoprc.example
!/.config/zsh/_.zsh
!/.config/zsh/alias.zsh
!/.config/zsh/alias/buildah.zsh
!/.config/zsh/alias/containers.zsh
!/.config/zsh/alias/diff.zsh
!/.config/zsh/alias/directories.zsh
!/.config/zsh/alias/git.zsh
@ -20,7 +20,6 @@
!/.config/zsh/alias/k8s.zsh
!/.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
@ -53,6 +52,7 @@
!/.config/zsh/lib/term.zsh
!/.config/zsh/lib/time.zsh
!/.config/zsh/lib/title.zsh
!/.config/zsh/local.zsh.example
!/.config/zsh/local/.keep
!/.config/zsh/opt.zsh
!/.config/zsh/opt/chase.zsh

View File

@ -1,3 +0,0 @@
#!/bin/zsh
alias bud='buildah bud --isolation chroot --network host --format docker -f '

View File

@ -0,0 +1,45 @@
#!/bin/zsh
alias bud='buildah bud --isolation chroot --network host --format docker -f '
alias pod-run='podman run -e "TERM=${TERM:-linux}" --network host --rm -it '
alias pod-run-sh="pod-run --entrypoint='[\"/bin/sh\"]' --user=0:0 "
alias pod-ps='podman ps '
alias pod-images='podman images --format "table {{.ID}} {{.Repository}}:{{.Tag}} {{.Size}} {{.Created}} |{{.CreatedAt}}" '
alias pod-inspect='podman inspect '
alias pod-logs='podman logs '
sko-inspect() {
command skopeo inspect "docker://${1:?}"
}
sko-list-tags() {
command skopeo list-tags "docker://${1:?}"
}
pod-dive() {
command dive "podman://${1:?}"
}
jq-visual() {
jq -C | less
}
jq-config() {
jq '.[].Config'
}
jq-tags() {
jq -r '.Tags[]'
}
if [ ${UID} -ne 0 ] ; then
alias docker='sudo docker '
fi
alias dkr='docker '
alias dkr-run='dkr run -e "TERM=${TERM:-linux}" --network host --rm -it '
alias dkr-run-sh="dkr-run --entrypoint='' --user=0:0 "
alias dkr-ps='dkr ps '
alias dkr-images='dkr images --format "table {{.ID}}\\t{{.Repository}}:{{.Tag}}\\t{{.Size}}\\t{{.CreatedAt}}" '
alias dkr-inspect='dkr inspect '
alias dkr-logs='dkr logs '

View File

@ -1,4 +0,0 @@
#!/bin/zsh
alias run='podman run -e "TERM=$TERM" --network host --rm -it '
alias run-sh="run --entrypoint='[\"/bin/sh\"]' --user=0:0 "

View File

@ -1,4 +1,10 @@
#!/bin/zsh
alias sudo-i='sudo -i '
alias sudoi='sudo -i '
function {
local c
if [ ${UID} -ne 0 ] ; then
c='sudo -i '
fi
alias sudo-i="$c"
alias sudoi="$c"
}

View File

@ -1,9 +1,28 @@
#!/bin/zsh
__z_comp__kubectl() { command kubectl completion zsh ; }
__z_comp__podman() { command podman completion zsh ; }
typeset -A ZSHU_COMP_EXTERNAL
for i ( kubectl podman ) ; do
__z_comp_external $i "__z_comp__$i"
for i ( kubectl podman skopeo docker ) ; do
ZSHU_COMP_EXTERNAL[$i]="command $i completion zsh"
done ; unset i
unset -fm '__z_comp__*'
# ZSHU_COMP_EXTERNAL[yq]='command yq shell-completion zsh'
## example of "automatic" shell completion generation
__z_comp_ext__yq() { command yq shell-completion zsh ; }
## example of more complex shell completion generation
# __z_comp__shifty_nifty() { command shifty-nifty completion zsh | sed -E 's/shifty_nifty/shifty-nifty/g' ; }
# ZSHU_COMP_EXTERNAL[shifty-nifty]='__z_comp__shifty_nifty'
z-comp-auto() {
local c f
for c ( ${(k)ZSHU_COMP_EXTERNAL} ) ; do
__z_comp_external "$c" "${(@s: :)ZSHU_COMP_EXTERNAL[$c]}" && unset "ZSHU_COMP_EXTERNAL[$c]"
done
for f ( ${functions[(I)__z_comp_ext__*]} ) ; do
c=${f#__z_comp_ext__}
__z_comp_external $c $f && unset -f "$f"
done
}
z-comp-auto

View File

@ -42,6 +42,7 @@ __z_compdump_finalize() {
unset 'ZSHU[compdump_meta]'
}
## TODO: refactor (e.g. buildah completion is a "bit" broken)
__z_comp_bash() {
local f p x
@ -62,16 +63,25 @@ __z_comp_bash() {
}
__z_comp_external() {
local f
local c f
c="$1" ; shift
(( ${+commands[$1]} )) || return 1
(( ${+_comps[$1]} )) && return 2
[ $# -gt 0 ] || return 1
f="${ZSHU[d_cache]}/completion/_$1"
if ! [ -s "$f" ] ; then
"$2" > "$f" || return 3
(( ${+commands[$c]} )) || return 2
if ! (( ${+ZSHU_COMP_FORCE[$c]} )) ; then
(( ${+_comps[$c]} )) && return
fi
autoload -Uz "_$1"
f="${ZSHU[d_cache]}/completion/_$c"
if ! [ -s "$f" ] ; then
if ! "$@" > "$f" ; then
rm -f "$f"
return 3
fi
fi
autoload -Uz "_$c"
return 0
}

View File

@ -0,0 +1,4 @@
#!/bin/zsh
typeset -gA ZSHU_COMP_FORCE
ZSHU_COMP_FORCE[podman]=1