From b6b9abdf05e906a51a6029d3ef2a5a335bcc4e6c Mon Sep 17 00:00:00 2001 From: Marc Khouzam Date: Wed, 15 Feb 2023 17:18:48 -0500 Subject: [PATCH] Allow sourcing zsh completion script Although it is not the recommended approach, sourcing a completion script is the simplest way to get people to try using shell completion. Not allowing it for zsh has turned out to complicate shell completion adoption. Further, many tools modify the zsh script to allow sourcing. This commit allows sourcing of the zsh completion script. Signed-off-by: Marc Khouzam --- completions.go | 2 +- zsh_completions.go | 1 + 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/completions.go b/completions.go index c7b457eb2..9a6effdb2 100644 --- a/completions.go +++ b/completions.go @@ -734,7 +734,7 @@ to enable it. You can execute the following once: To load completions in your current shell session: - source <(%[1]s completion zsh); compdef _%[1]s %[1]s + source <(%[1]s completion zsh) To load completions for every new session, execute once: diff --git a/zsh_completions.go b/zsh_completions.go index 29bcb570a..305a19d93 100644 --- a/zsh_completions.go +++ b/zsh_completions.go @@ -90,6 +90,7 @@ func genZshComp(buf io.StringWriter, name string, includeDesc bool) { compCmd = ShellCompNoDescRequestCmd } WriteStringAndCheck(buf, fmt.Sprintf(`#compdef %[1]s +compdef _%[1]s %[1]s # zsh completion for %-36[1]s -*- shell-script -*-