Skip to content

Commit dd79ddf

Browse files
authored
Lazy completion loading for Zsh (#475)
Fixes #473
1 parent 521082e commit dd79ddf

File tree

1 file changed

+10
-2
lines changed

1 file changed

+10
-2
lines changed

argcomplete/shell_integration.py

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55

66
from shlex import quote
77

8-
bashcode = r"""
8+
bashcode = r"""#compdef %(executables)s
99
# Run something, muting output or redirecting it to the debug stream
1010
# depending on the value of _ARC_DEBUG.
1111
# If ARGCOMPLETE_USE_TEMPFILES is set, use tempfiles for IPC.
@@ -75,8 +75,16 @@
7575
if [[ -z "${ZSH_VERSION-}" ]]; then
7676
complete %(complete_opts)s -F _python_argcomplete%(function_suffix)s %(executables)s
7777
else
78+
# When called by the Zsh completion system, this will end with
79+
# "loadautofunc" when initially autoloaded and "shfunc" later on, otherwise,
80+
# the script was "eval"-ed so use "compdef" to register it with the
81+
# completion system
7882
autoload is-at-least
79-
compdef _python_argcomplete%(function_suffix)s %(executables)s
83+
if [[ $zsh_eval_context == *func ]]; then
84+
_python_argcomplete%(function_suffix)s "$@"
85+
else
86+
compdef _python_argcomplete%(function_suffix)s %(executables)s
87+
fi
8088
fi
8189
"""
8290

0 commit comments

Comments
 (0)