From 7bf6262945692687b95fea73a1002b3fe0c07c0b Mon Sep 17 00:00:00 2001 From: Konstantin Demin Date: Mon, 22 Mar 2021 22:57:36 +0300 Subject: [PATCH] modify external completion routines --- .../zsh/local => .cache/zsh}/completion/.keep | 0 .config/dotfiles/gitignore | 2 +- .config/zsh/completion/podman.zsh | 4 +++- .config/zsh/lib/completion.zsh | 17 ++++++++--------- 4 files changed, 12 insertions(+), 11 deletions(-) rename {.config/zsh/local => .cache/zsh}/completion/.keep (100%) diff --git a/.config/zsh/local/completion/.keep b/.cache/zsh/completion/.keep similarity index 100% rename from .config/zsh/local/completion/.keep rename to .cache/zsh/completion/.keep diff --git a/.config/dotfiles/gitignore b/.config/dotfiles/gitignore index 01831a2..9437d83 100644 --- a/.config/dotfiles/gitignore +++ b/.config/dotfiles/gitignore @@ -1,6 +1,7 @@ * !/.cache/zsh/.keep !/.cache/zsh/compcache/.keep +!/.cache/zsh/completion/.keep !/.config/dotfiles/bin/.keep !/.config/dotfiles/gen-gitignore.sh !/.config/dotfiles/gitignore @@ -38,7 +39,6 @@ !/.config/zsh/lib/starship.zsh.sample !/.config/zsh/lib/time.zsh !/.config/zsh/local/.keep -!/.config/zsh/local/completion/.keep !/.config/zsh/opt.zsh !/.config/zsh/opt/chase.zsh !/.config/zsh/opt/completion.zsh diff --git a/.config/zsh/completion/podman.zsh b/.config/zsh/completion/podman.zsh index 7a9f698..0f1fcae 100644 --- a/.config/zsh/completion/podman.zsh +++ b/.config/zsh/completion/podman.zsh @@ -1,3 +1,5 @@ #!/bin/zsh -__z_comp_test podman && podman completion zsh | __z_comp_write podman +__z_comp_podman() { command podman completion zsh ; } +__z_comp_external podman __z_comp_podman +unset -f __z_comp_podman diff --git a/.config/zsh/lib/completion.zsh b/.config/zsh/lib/completion.zsh index c196019..f5d0fe1 100644 --- a/.config/zsh/lib/completion.zsh +++ b/.config/zsh/lib/completion.zsh @@ -4,7 +4,7 @@ ZSHU[f_compdump]="${ZSHU[d_cache]}/compdump" ZSHU[d_compcache]="${ZSHU[d_cache]}/compcache" [ -d "${ZSHU[d_compcache]}" ] || mkdir -p "${ZSHU[d_compcache]}" -fpath=( "${ZSHU[d_compcache]}" $fpath ) +fpath=( "${ZSHU[d_cache]}/completion" $fpath ) __z_compdump_print() { printf '#zshu %s %s\n' "$1" "${(P)1}" ; } @@ -56,14 +56,13 @@ __z_comp_bash() { return 0 } -__z_comp_test() { +__z_comp_external() { (( ${+commands[$1]} )) || return 1 - (( ${+_comps[$1]} )) && return 2 - [ -s "${ZSHU[d_compcache]}/_$1" ] && return 3 - return 0 -} - -__z_comp_write() { - cat > "${ZSHU[d_compcache]}/_$1" + (( ${+_comps[$1]} )) && return 2 + local f="${ZSHU[d_cache]}/completion/_$1" + if ! [ -s "$f" ] ; then + "$2" > "$f" || return 3 + fi + autoload -Uz "_$1" return 0 }