Skip to content

Commit

Permalink
Fix continuation chars in zsh
Browse files Browse the repository at this point in the history
  • Loading branch information
evanunderscore committed Nov 25, 2023
1 parent 995f8d9 commit 02e1a72
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 13 deletions.
14 changes: 10 additions & 4 deletions argcomplete/bash_completion.d/_python-argcomplete
Original file line number Diff line number Diff line change
Expand Up @@ -139,9 +139,6 @@ _python_argcomplete_global() {
__python_argcomplete_expand_tilde_by_ref executable
else
if [[ "$service" != "-default-" ]]; then
# TODO: this may not be sufficient - see https://zsh.sourceforge.io/Doc/Release/Completion-System.html
# May need to call _complete with avoid-completer=_python-argcomplete or something like that
_default
return
fi
executable="${words[1]}"
Expand Down Expand Up @@ -208,7 +205,15 @@ _python_argcomplete_global() {
_ARGCOMPLETE_SHELL="zsh" \
_ARGCOMPLETE_SUPPRESS_SPACE=1 \
__python_argcomplete_run "$executable" "${(@)req_argv[1, ${ARGCOMPLETE}-1]}"))
_describe "$executable" completions
local nosort=()
local nospace=()
if is-at-least 5.8; then
nosort=(-o nosort)
fi
if [[ "${completions-}" =~ ([^\\]): && "${BASH_REMATCH[2]}" =~ [=/:] ]]; then
nospace=(-S '')
fi
_describe "$executable" completions "${nosort[@]}" "${nospace[@]}"
else
COMPREPLY=($(IFS="$IFS" \
COMP_LINE="$COMP_LINE" \
Expand All @@ -234,5 +239,6 @@ _python_argcomplete_global() {
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 '*'
fi
11 changes: 10 additions & 1 deletion argcomplete/shell_integration.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,15 @@
_ARGCOMPLETE_SHELL="zsh" \
_ARGCOMPLETE_SUPPRESS_SPACE=1 \
__python_argcomplete_run ${script:-${words[1]}}))
_describe "${words[1]}" completions -o nosort
local nosort=()
local nospace=()
if is-at-least 5.8; then
nosort=(-o nosort)
fi
if [[ "${completions-}" =~ ([^\\]): && "${match[1]}" =~ [=/:] ]]; then
nospace=(-S '')
fi
_describe "${words[1]}" completions "${nosort[@]}" "${nospace[@]}"
else
local SUPPRESS_SPACE=0
if compopt +o nospace 2> /dev/null; then
Expand All @@ -67,6 +75,7 @@
if [[ -z "${ZSH_VERSION-}" ]]; then
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
fi
"""
Expand Down
24 changes: 16 additions & 8 deletions test/test.py
Original file line number Diff line number Diff line change
Expand Up @@ -1248,9 +1248,6 @@ def setUp(self):
path = ":".join([os.path.join(BASE_DIR, "scripts"), TEST_DIR, "$PATH"])
sh.run_command("export PATH={0}".format(path))
sh.run_command("export PYTHONPATH={0}".format(BASE_DIR))
if self.repl_provider == bash_repl:
# Disable the "python" module provided by bash-completion
sh.run_command("complete -r python python2 python3")
output = sh.run_command(self.install_cmd)
self.assertEqual(output, "")
# Register a dummy completion with an external argcomplete script
Expand Down Expand Up @@ -1300,21 +1297,23 @@ def test_nounset(self):


class TestZsh(TestBashZshBase, unittest.TestCase):
skipped = [
expected_failures = [
"test_parse_special_characters",
"test_parse_special_characters_dollar",
"test_comp_point", # FIXME
"test_completion_environment", # FIXME
"test_continuation", # FIXME
"test_wordbreak_chars", # FIXME
]

def setUp(self):
super().setUp()
# Require two tabs to print all options (some tests rely on this).
self.sh.run_command("setopt BASH_AUTO_LIST")

def repl_provider(self):
return zsh_repl()


@unittest.skipIf(BASH_MAJOR_VERSION < 4, "complete -D not supported")
class TestBashGlobal(TestBash):
class TestBashZshGlobalBase(TestBashZshBase):
install_cmd = 'eval "$(activate-global-python-argcomplete --dest=-)"'

def test_python_completion(self):
Expand Down Expand Up @@ -1388,6 +1387,15 @@ def test_console_script_package_wheel(self):
self._test_console_script(package=True, wheel=True)


@unittest.skipIf(BASH_MAJOR_VERSION < 4, "complete -D not supported")
class TestBashGlobal(TestBash, TestBashZshGlobalBase):
pass


class TestZshGlobal(TestZsh, TestBashZshGlobalBase):
pass


class Shell:
def __init__(self, shell):
self.child = pexpect.spawn(shell, encoding="utf-8")
Expand Down

0 comments on commit 02e1a72

Please sign in to comment.