From ec241eea1b1639938ba2e54e2b8ae601431224e2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?M=C3=A9sz=C3=A1ros=20Gergely?= Date: Tue, 14 May 2024 14:47:01 +0200 Subject: [PATCH] BUG: ZSH Autocomplete does not work if installed as a file #2955 (#2956) --- commands/completion-scripts/completion.zsh.gotmpl | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/commands/completion-scripts/completion.zsh.gotmpl b/commands/completion-scripts/completion.zsh.gotmpl index 665a361ec..1eb219175 100644 --- a/commands/completion-scripts/completion.zsh.gotmpl +++ b/commands/completion-scripts/completion.zsh.gotmpl @@ -1,4 +1,4 @@ -#compdef "{{.App.Name}}" +#compdef {{.App.Name}} _dnscontrol() { local -a opts @@ -17,4 +17,12 @@ _dnscontrol() { fi } -compdef "_dnscontrol" "{{.App.Name}}" +# Run the function the first time we are auto-loaded, otherwise the very first +# complete wouldn't work in each shell session +# Otherwise assume we are directly sourced and register the completion +# (This is done by the #compdef directive in the autoloaded case.) +if [[ "${zsh_eval_context[-1]}" == "loadautofunc" ]]; then + _dnscontrol "$@" +else + compdef "_dnscontrol" "dnscontrol" +fi