From dd75cc35d6b8d6d7efd20cbe40c5ad5dd0f0baa4 Mon Sep 17 00:00:00 2001 From: Segev Finer Date: Mon, 26 Feb 2024 14:52:25 +0200 Subject: [PATCH 1/2] Lazy completion loading for Zsh Fixes #473 --- argcomplete/shell_integration.py | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/argcomplete/shell_integration.py b/argcomplete/shell_integration.py index 73214bb6..c41e194a 100644 --- a/argcomplete/shell_integration.py +++ b/argcomplete/shell_integration.py @@ -5,7 +5,7 @@ from shlex import quote -bashcode = r""" +bashcode = r"""#compdef %(executables)s # Run something, muting output or redirecting it to the debug stream # depending on the value of _ARC_DEBUG. # If ARGCOMPLETE_USE_TEMPFILES is set, use tempfiles for IPC. @@ -76,7 +76,11 @@ complete %(complete_opts)s -F _python_argcomplete%(function_suffix)s %(executables)s else autoload is-at-least - compdef _python_argcomplete%(function_suffix)s %(executables)s + if [[ $zsh_eval_context == *func ]]; then + _python_argcomplete%(function_suffix)s "$@" + else + compdef _python_argcomplete%(function_suffix)s %(executables)s + fi fi """ From faf8ee068e49360f7e548ed1159236105ec0f943 Mon Sep 17 00:00:00 2001 From: Segev Finer Date: Sun, 3 Mar 2024 21:33:53 +0200 Subject: [PATCH 2/2] Add comment --- argcomplete/shell_integration.py | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/argcomplete/shell_integration.py b/argcomplete/shell_integration.py index c41e194a..e84f507d 100644 --- a/argcomplete/shell_integration.py +++ b/argcomplete/shell_integration.py @@ -75,6 +75,10 @@ if [[ -z "${ZSH_VERSION-}" ]]; then complete %(complete_opts)s -F _python_argcomplete%(function_suffix)s %(executables)s else + # When called by the Zsh completion system, this will end with + # "loadautofunc" when initially autoloaded and "shfunc" later on, otherwise, + # the script was "eval"-ed so use "compdef" to register it with the + # completion system autoload is-at-least if [[ $zsh_eval_context == *func ]]; then _python_argcomplete%(function_suffix)s "$@"