From 1f6e66148ae8a4225481b4f3a9ae054d462cede0 Mon Sep 17 00:00:00 2001 From: Evan Date: Sun, 26 Nov 2023 00:15:31 +1100 Subject: [PATCH] Fix completion in zsh special contexts --- argcomplete/bash_completion.d/_python-argcomplete | 8 ++++---- test/test.py | 9 +++++++++ 2 files changed, 13 insertions(+), 4 deletions(-) diff --git a/argcomplete/bash_completion.d/_python-argcomplete b/argcomplete/bash_completion.d/_python-argcomplete index 2cbc3962..cdb60a96 100644 --- a/argcomplete/bash_completion.d/_python-argcomplete +++ b/argcomplete/bash_completion.d/_python-argcomplete @@ -138,9 +138,6 @@ _python_argcomplete_global() { req_argv=( "" "${COMP_WORDS[@]:1}" ) __python_argcomplete_expand_tilde_by_ref executable else - if [[ "$service" != "-default-" ]]; then - return - fi executable="${words[1]}" req_argv=( "${words[@]:1}" ) fi @@ -240,5 +237,8 @@ if [[ -z "${ZSH_VERSION-}" ]]; then complete -o default -o bashdefault -D -F _python_argcomplete_global else autoload is-at-least - compdef _python_argcomplete_global -P '*' + # Replace only the default completer (_default). + # There are many other special contexts we don't want to override. + # https://zsh.sourceforge.io/Doc/Release/Completion-System.html + compdef _python_argcomplete_global -default- fi diff --git a/test/test.py b/test/test.py index ae4ed0a8..9868bbfe 100755 --- a/test/test.py +++ b/test/test.py @@ -1313,6 +1313,15 @@ def repl_provider(self): class TestBashZshGlobalBase(TestBashZshBase): install_cmd = 'eval "$(activate-global-python-argcomplete --dest=-)"' + def test_redirection_completion(self): + with TempDir(prefix="test_dir_py", dir="."): + self.sh.run_command("cd " + os.getcwd()) + self.sh.run_command("echo failure > ./foo.txt") + self.sh.run_command("echo success > ./foo.\t") + with open("foo.txt") as f: + msg = f.read() + self.assertEqual(msg, "success\n") + def test_python_completion(self): self.sh.run_command("cd " + TEST_DIR) self.assertEqual(self.sh.run_command("python3 ./prog basic f\t"), "foo\r\n")