Skip to content

Commit 9b73482

Browse files
authored
Fix zsh completion script (#12173)
2 parents b551c09 + dba399f commit 9b73482

File tree

3 files changed

+25
-6
lines changed

3 files changed

+25
-6
lines changed

news/12166.bugfix.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Fix completion script for zsh

src/pip/_internal/commands/completion.py

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -23,9 +23,18 @@
2323
""",
2424
"zsh": """
2525
#compdef -P pip[0-9.]#
26-
compadd $( COMP_WORDS="$words[*]" \\
27-
COMP_CWORD=$((CURRENT-1)) \\
28-
PIP_AUTO_COMPLETE=1 $words[1] 2>/dev/null )
26+
__pip() {{
27+
compadd $( COMP_WORDS="$words[*]" \\
28+
COMP_CWORD=$((CURRENT-1)) \\
29+
PIP_AUTO_COMPLETE=1 $words[1] 2>/dev/null )
30+
}}
31+
if [[ $zsh_eval_context[-1] == loadautofunc ]]; then
32+
# autoload from fpath, call function directly
33+
__pip "$@"
34+
else
35+
# eval/source/. command, register function for later
36+
compdef __pip -P 'pip[0-9.]#'
37+
fi
2938
""",
3039
"fish": """
3140
function __fish_complete_pip

tests/functional/test_completion.py

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -44,9 +44,18 @@
4444
"zsh",
4545
"""\
4646
#compdef -P pip[0-9.]#
47-
compadd $( COMP_WORDS="$words[*]" \\
48-
COMP_CWORD=$((CURRENT-1)) \\
49-
PIP_AUTO_COMPLETE=1 $words[1] 2>/dev/null )""",
47+
__pip() {
48+
compadd $( COMP_WORDS="$words[*]" \\
49+
COMP_CWORD=$((CURRENT-1)) \\
50+
PIP_AUTO_COMPLETE=1 $words[1] 2>/dev/null )
51+
}
52+
if [[ $zsh_eval_context[-1] == loadautofunc ]]; then
53+
# autoload from fpath, call function directly
54+
__pip "$@"
55+
else
56+
# eval/source/. command, register function for later
57+
compdef __pip -P 'pip[0-9.]#'
58+
fi""",
5059
),
5160
(
5261
"powershell",

0 commit comments

Comments
 (0)