Skip to content

Commit 7e5cff2

Browse files
author
Stephane Chazelas
committed
fix bash completion when the user has changed $IFS
Like in the Korn shell, "${COMP_WORDS[*]}" in bash joins the elements of the array with the first character of $IFS, and $(...) and $1 unquoted cause their expansion to be split on characters of $IFS (and be subjected to globbing). Here, we want the COMP_WORDS elements to be joined with space characters and $(...) to be split on space (and possibly tab and newline in the future) like with the default value of $IFS (or when $IFS is unset). So we set IFS locally to space+tab+newline (better than "local IFS" alone which would only make IFS unset in the function if the localvar_inherit option was not enabled (bash has no equivalent of zsh's "emulate -L zsh" to have default option settings locally in a function)). Globbing is still performed on the resulting words (unless the user enabled the noglob option), which is still a problem for instance when we offer file or directory completions when files/directories paths contain wildcard characters, but then again at the moment any character special in the syntax of the shell (including wildcards, space, ;|()<> etc) are a problem anyway as we don't quote them like bash's default file completion does, so it's probably not worth fixing until that other issue is addressed. At the moment pip's file completion only works properly on very tame file names. The ash-style "local -; set -o noglob" which would be the obvious fix for that wouldn't work with the ancient version of bash found on macos.
1 parent 5455edc commit 7e5cff2

File tree

2 files changed

+3
-1
lines changed

2 files changed

+3
-1
lines changed

news/13555.bugfix.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Fix bash completion when the ``$IFS`` variable has been modified from its default.

src/pip/_internal/commands/completion.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,9 +14,10 @@
1414
"bash": """
1515
_pip_completion()
1616
{{
17+
local IFS=$' \\t\\n'
1718
COMPREPLY=( $( COMP_WORDS="${{COMP_WORDS[*]}}" \\
1819
COMP_CWORD=$COMP_CWORD \\
19-
PIP_AUTO_COMPLETE=1 $1 2>/dev/null ) )
20+
PIP_AUTO_COMPLETE=1 "$1" 2>/dev/null ) )
2021
}}
2122
complete -o default -F _pip_completion {prog}
2223
""",

0 commit comments

Comments
 (0)