Skip to content

Commit

Permalink
Allow explicit zsh global completion activation (#467)
Browse files Browse the repository at this point in the history
  • Loading branch information
evanunderscore authored Dec 10, 2023
1 parent 3274413 commit 568d327
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 6 deletions.
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

0 comments on commit 568d327

Please sign in to comment.