Skip to content

Commit

Permalink
zsh: allow to eval zsh completion
Browse files Browse the repository at this point in the history
Allow to run `eval "$(my-prog --print-completion zsh)"` to enable
completion in the current zsh environment. This change is inspired by
pypa/pip#12173 and pallets/click#2544.
  • Loading branch information
bjoernricks committed Jan 31, 2024
1 parent eb12748 commit c2a6f38
Showing 1 changed file with 9 additions and 1 deletion.
10 changes: 9 additions & 1 deletion shtab/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -659,7 +659,15 @@ def command_list(prefix, options):
${preamble}
typeset -A opt_args
${root_prefix} "$@\"""").safe_substitute(
if [[ $zsh_eval_context[-1] == eval ]]; then
# eval/source/. command, register function for later
compdef ${root_prefix} -N ${prog}
else
# autoload from fpath, call function directly
${root_prefix} "$@\"
fi
""").safe_substitute(
prog=prog,
root_prefix=root_prefix,
command_cases="\n".join(starmap(command_case, sorted(subcommands.items()))),
Expand Down

0 comments on commit c2a6f38

Please sign in to comment.