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

Allow explicit zsh global completion activation #467

Merged
merged 1 commit into from
Dec 10, 2023
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
14 changes: 12 additions & 2 deletions argcomplete/bash_completion.d/_python-argcomplete
Original file line number Diff line number Diff line change
Expand Up @@ -244,7 +244,17 @@ else
# -Uz is recommended for the use of functions supplied with the zsh distribution.
# https://unix.stackexchange.com/a/214306
autoload -Uz is-at-least
# The comment at the top of this file causes zsh to invoke this script directly,
# If this is being implicitly loaded because we placed it on fpath,
# the comment at the top of this file causes zsh to invoke this script directly,
# so we must explicitly call the global completion function.
_python_argcomplete_global
# Note $service should only ever be -default- because the comment at the top
# registers this script as the default completer (#compdef -default-).
if [[ $service == -default- ]]; then
_python_argcomplete_global
fi
# If this has been executed directly (e.g. `eval "$(activate-global-python-argcomplete --dest=-)"`)
# we need to explicitly call compdef to register the completion function.
# If we have been implicitly loaded, we still call compdef as a slight optimisation
# (there is no need to execute any top-level code more than once).
compdef _python_argcomplete_global -default-
fi
10 changes: 6 additions & 4 deletions test/test.py
Original file line number Diff line number Diff line change
Expand Up @@ -1409,11 +1409,13 @@ class TestBashGlobal(TestBash, TestBashZshGlobalBase):
pass


class TestZshGlobal(TestZsh, TestBashZshGlobalBase):
# In zsh, the file is not sourced directly;
class TestZshGlobalExplicit(TestZsh, TestBashZshGlobalBase):
pass


class TestZshGlobalImplicit(TestZsh, TestBashZshGlobalBase):
# In zsh, the file is typically not sourced directly;
# it is added to fpath and autoloaded by the completion system.
# Running `eval "$(activate-global-python-argcomplete --dest=-)"`
# as in bash does *not* work in zsh!
zsh_fpath = os.path.join(os.path.abspath(os.path.dirname(argcomplete.__file__)), "bash_completion.d")
init_cmd = f'fpath=( {zsh_fpath} "${{fpath[@]}}" ); autoload compinit; compinit -u'
install_cmd = None
Expand Down