Skip to content

Commit

Permalink
Merge pull request #159 from bjoernricks/zsh-eval-support
Browse files Browse the repository at this point in the history
  • Loading branch information
casperdcl authored Jan 31, 2024
2 parents eb12748 + 6b3c4f3 commit e69727c
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 3 deletions.
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

0 comments on commit e69727c

Please sign in to comment.