Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

zsh: allow to eval zsh completion #159

Merged
merged 4 commits into from
Jan 31, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
5 changes: 3 additions & 2 deletions tests/test_shtab.py
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,8 @@ def test_prog_scripts(shell, caplog, capsys):
elif shell == "zsh":
assert script_py == [
"#compdef script.py", "_describe 'script.py commands' _commands",
"_shtab_shtab_options+=(': :_shtab_shtab_commands' '*::: :->script.py')", "script.py)"]
"_shtab_shtab_options+=(': :_shtab_shtab_commands' '*::: :->script.py')", "script.py)",
"compdef _shtab_shtab -N script.py"]
elif shell == "tcsh":
assert script_py == ["complete script.py \\"]
else:
Expand Down Expand Up @@ -271,7 +272,7 @@ def test_add_argument_to_positional(shell, caplog, capsys):
assert exc.value.code == 0
completion, err = capsys.readouterr()
print(completion)
assert completion_manual == completion.rstrip()
assert completion_manual.rstrip() == completion.rstrip()
assert not err

if shell == "bash":
Expand Down
Loading