fix bash completion when the user has changed $IFS (#13555) #13558
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Fixes #13555
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 thelocalvar_inherit
option was not enabled (bash has no equivalent of zsh'semulate -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.