Skip to content
Myr

Fix zsh completion not working on the first time in a shell session (#1237)

Before adoption: this commit came in with the history the project adopted, so no landing records it.

The zsh completion script output by cobra is a stub completion function which replaces itself with the actual completion function. This technique enables cobra to define helper functions without splitting the completion script into multiple files. However, the current implementation forgets to call the actual completion function at the end of the stub function, meaning that completion won't work the first time it's invoked in a shell session. This commit is a fix for this problem.

authored by midchildan · committed by GitHub · parent 40d34bc · Browse files · 1 file+5 added−0 removed
This commit

State

Before adoption: this commit came in with the history the project adopted, so no landing records it.

Diff stats

1 file+5 added−0 removed

  • other:+5 added−0 removed

1 file+5 added−0 removed

modified:zsh_completions.go+5 added
227 unmodified lines
228 else229 _describe "completions" completions $(echo $flagPrefix)230 fi231}232233# don't run the completion function when being source-ed or eval-ed234if [ "$funcstack[1]" = "_%[1]s" ]; then235 _%[1]s236fi237`, name, compCmd,238 ShellCompDirectiveError, ShellCompDirectiveNoSpace, ShellCompDirectiveNoFileComp,239 ShellCompDirectiveFilterFileExt, ShellCompDirectiveFilterDirs))240}