Skip to content

Commit

Permalink
Support Zsh completion autoload
Browse files Browse the repository at this point in the history
With this, you can just dump the script in your Zsh fpath and it will be loaded as needed by the completion system

Fixes pnpm/pnpm#8232
  • Loading branch information
segevfiner committed Jun 24, 2024
1 parent c0c4848 commit f5450be
Showing 1 changed file with 10 additions and 1 deletion.
11 changes: 10 additions & 1 deletion lib/templates/completion.zsh
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
#compdef {pkgname}
###-begin-{pkgname}-completion-###
if type compdef &>/dev/null; then
_{pkgname}_completion () {
Expand All @@ -13,6 +14,14 @@ if type compdef &>/dev/null; then
_describe 'values' reply
fi
}
compdef _{pkgname}_completion {pkgname}
# When called by the Zsh completion system, this will end with
# "loadautofunc" when initially autoloaded and "shfunc" later on, otherwise,
# the script was "eval"-ed so use "compdef" to register it with the
# completion system
if [[ $zsh_eval_context == *func ]]; then
_{pkgname}_completion "$@"
else
compdef _{pkgname}_completion {pkgname}
fi
fi
###-end-{pkgname}-completion-###

0 comments on commit f5450be

Please sign in to comment.