From 6d748260e8b3cea10ce0f501ab5c1180223d8c44 Mon Sep 17 00:00:00 2001 From: Tobias Gruetzmacher Date: Thu, 12 Sep 2024 18:08:26 +0200 Subject: [PATCH] Add setup for mise-en-place --- zsh/funcs/_cache-completion | 14 ++++++++++++++ zsh/rc.apps | 8 ++++++++ zsh/rc.k8s | 7 +------ zsh/rc.python | 8 +------- 4 files changed, 24 insertions(+), 13 deletions(-) create mode 100644 zsh/funcs/_cache-completion diff --git a/zsh/funcs/_cache-completion b/zsh/funcs/_cache-completion new file mode 100644 index 0000000..b9f293d --- /dev/null +++ b/zsh/funcs/_cache-completion @@ -0,0 +1,14 @@ +# Generate a completion function from the output of a specific command, but +# only if the binary is newer then the completion script + +local funcdir="${XDG_CACHE_HOME:-$HOME/.cache}/zsh/funcs" +local bin="$1" +local cmd="$2" +local target="$funcdir/_$bin:t" + +if [[ ! -e "$target" || "$target" -ot "$bin" ]] +then + mkdir -p "$funcdir" + $=cmd > "$target" +fi + diff --git a/zsh/rc.apps b/zsh/rc.apps index 6469982..266008c 100644 --- a/zsh/rc.apps +++ b/zsh/rc.apps @@ -91,6 +91,14 @@ then } fi +# mise-en-place +if [[ -x =mise ]] +then + eval "$(mise activate zsh)" + # TAB completion needs the "usage" tool (install with "mise use -g usage") + [[ -x =usage ]] && _cache-completion =mise "mise completion zsh" +fi + # PostgreSQL XDG redirects if [[ -x =psql ]] then diff --git a/zsh/rc.k8s b/zsh/rc.k8s index dd61156..88000e7 100644 --- a/zsh/rc.k8s +++ b/zsh/rc.k8s @@ -2,12 +2,7 @@ if [[ -x =kubectl ]] then funcdir="${XDG_CACHE_HOME:-$HOME/.cache}/zsh/funcs" - mkdir -p "$funcdir" - if [[ ! -e "$funcdir/_kubectl" || "$funcdir/_kubectl" -ot =kubectl ]] - then - kubectl completion zsh > "$funcdir/_kubectl" - fi - unset funcdir + _cache-completion =kubectl "kubectl completion zsh" alias k='kubectl' diff --git a/zsh/rc.python b/zsh/rc.python index 8c79e72..de8440e 100644 --- a/zsh/rc.python +++ b/zsh/rc.python @@ -49,13 +49,7 @@ unset p register_argcomp if [[ -x =poetry ]] then - funcdir="${XDG_CACHE_HOME:-$HOME/.cache}/zsh/funcs" - mkdir -p "$funcdir" - if [[ ! -f "$funcdir/_poetry" || "$funcdir/_poetry" -ot =poetry ]] - then - poetry completions zsh > "$funcdir/_poetry" - fi - unset funcdir + _cache-completion =poetry "poetry completions zsh" fi # vim: set ts=4 sw=4 ft=zsh: