Skip to content

Commit ea39680

Browse files
authored
Merge pull request #918 from akinomyoga/quote-split
fix: quote `$split` of `$split && return` for custom IFS
2 parents cb306a6 + 44c4327 commit ea39680

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

161 files changed

+414
-361
lines changed

bash_completion

Lines changed: 15 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -983,21 +983,21 @@ _comp_variable_assignments()
983983
# argument $2 is the string before the cursor in the
984984
# current word. The third argument $3 is the previous
985985
# word.
986-
# @var[out] cur Reconstructed current word
987-
# @var[out] prev Reconstructed previous word
988-
# @var[out] words Reconstructed words
989-
# @var[out] cword Current word index in `words`
990-
# @var[out] comp_args Original arguments specified to the completion function
991-
# are saved in this array, if the arguments $1...$3 is
992-
# specified.
993-
# @var[out,opt] split When "-s" is specified, `true/false` is set depending on
994-
# whether the split happened.
986+
# @var[out] cur Reconstructed current word
987+
# @var[out] prev Reconstructed previous word
988+
# @var[out] words Reconstructed words
989+
# @var[out] cword Current word index in `words`
990+
# @var[out] comp_args Original arguments specified to the completion function
991+
# are saved in this array, if the arguments $1...$3 is
992+
# specified.
993+
# @var[out,opt] was_split When "-s" is specified, `"set"/""` is set depending
994+
# on whether the split happened.
995995
# @return True (0) if completion needs further processing,
996996
# False (> 0) no further processing is necessary.
997997
#
998998
_comp_initialize()
999999
{
1000-
local exclude="" outx errx inx
1000+
local exclude="" opt_split="" outx errx inx
10011001

10021002
local flag OPTIND=1 OPTARG="" OPTERR=0
10031003
while getopts "n:e:o:i:s" flag "$@"; do
@@ -1007,7 +1007,8 @@ _comp_initialize()
10071007
o) outx=$OPTARG ;;
10081008
i) inx=$OPTARG ;;
10091009
s)
1010-
split=false
1010+
opt_split="set"
1011+
was_split=""
10111012
exclude+="="
10121013
;;
10131014
*)
@@ -1065,7 +1066,7 @@ _comp_initialize()
10651066
((cword <= 0)) && return 1
10661067
prev=${words[cword - 1]}
10671068

1068-
[[ ${split-} ]] && _split_longopt && split=true
1069+
[[ $opt_split ]] && _split_longopt && was_split="set"
10691070

10701071
return 0
10711072
}
@@ -2371,7 +2372,7 @@ _complete_as_root()
23712372

23722373
_longopt()
23732374
{
2374-
local cur prev words cword split comp_args
2375+
local cur prev words cword was_split comp_args
23752376
_comp_initialize -s -- "$@" || return
23762377

23772378
case "${prev,,}" in
@@ -2402,7 +2403,7 @@ _longopt()
24022403
;;
24032404
esac
24042405

2405-
$split && return
2406+
[[ $was_split ]] && return
24062407

24072408
if [[ $cur == -* ]]; then
24082409
_comp_compgen COMPREPLY -W "$(LC_ALL=C $1 --help 2>&1 |

bash_completion.d/000_bash_completion_compat.bash

Lines changed: 53 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@ _comp_deprecate_func _userland _comp_userland
44
_comp_deprecate_func _sysvdirs _comp_sysvdirs
55
_comp_deprecate_func _have _comp_have_command
66
_comp_deprecate_func _rl_enabled _comp_readline_variable_on
7-
_comp_deprecate_func _init_completion _comp_initialize
87
_comp_deprecate_func _command_offset _comp_command_offset
98
_comp_deprecate_func _command _comp_command
109
_comp_deprecate_func _root_command _comp_root_command
@@ -178,6 +177,59 @@ _realcommand()
178177
return $rc
179178
}
180179

180+
# Initialize completion and deal with various general things: do file
181+
# and variable completion where appropriate, and adjust prev, words,
182+
# and cword as if no redirections exist so that completions do not
183+
# need to deal with them. Before calling this function, make sure
184+
# cur, prev, words, and cword are local, ditto split if you use -s.
185+
#
186+
# Options:
187+
# -n EXCLUDE Passed to _comp_get_words -n with redirection chars
188+
# -e XSPEC Passed to _filedir as first arg for stderr redirections
189+
# -o XSPEC Passed to _filedir as first arg for other output redirections
190+
# -i XSPEC Passed to _filedir as first arg for stdin redirections
191+
# -s Split long options with _split_longopt, implies -n =
192+
# @var[out] cur Reconstructed current word
193+
# @var[out] prev Reconstructed previous word
194+
# @var[out] words Reconstructed words
195+
# @var[out] cword Current word index in `words`
196+
# @var[out,opt] split When "-s" is specified, `"true"/"false"` is set depending
197+
# on whether the split happened.
198+
# @return True (0) if completion needs further processing,
199+
# False (> 0) no further processing is necessary.
200+
#
201+
# @deprecated Use the new interface `_comp_initialize`. The new interface
202+
# supports the same set of options. The new interface receives additional
203+
# arguments $1 (command name), $2 (part of current word before the cursor), and
204+
# $3 (previous word) that are specified to the completion function by Bash.
205+
# When `-s` is specified, instead of variable `split`, the new interface sets
206+
# variable `was_split` to the value "set"/"" when the split happened/not
207+
# happened.
208+
_init_completion()
209+
{
210+
local was_split
211+
_comp_initialize "$@"
212+
local rc=$?
213+
214+
# When -s is specified, convert "split={set,}" to "split={true,false}"
215+
local flag OPTIND=1 OPTARG="" OPTERR=0
216+
while getopts "n:e:o:i:s" flag "$@"; do
217+
case $flag in
218+
[neoi]) ;;
219+
s)
220+
if [[ $was_split ]]; then
221+
split=true
222+
else
223+
split=false
224+
fi
225+
break
226+
;;
227+
esac
228+
done
229+
230+
return "$rc"
231+
}
232+
181233
# @deprecated Use the variable `_comp_backup_glob` instead. This is the
182234
# backward-compatibility name.
183235
# shellcheck disable=SC2154 # defined in the main "bash_completion"

completions/2to3

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
_comp_cmd_2to3()
44
{
5-
local cur prev words cword split comp_args
5+
local cur prev words cword was_split comp_args
66
_comp_initialize -s -- "$@" || return
77

88
case $prev in
@@ -24,7 +24,7 @@ _comp_cmd_2to3()
2424
;;
2525
esac
2626

27-
$split && return
27+
[[ $was_split ]] && return
2828

2929
if [[ $cur == -* ]]; then
3030
COMPREPLY=($(compgen -W '$(_parse_help "$1")' -- "$cur"))

completions/_mock

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55

66
_comp_cmd_mock()
77
{
8-
local cur prev words cword split comp_args
8+
local cur prev words cword was_split comp_args
99
_comp_initialize -s -- "$@" || return
1010

1111
local plugins='tmpfs root_cache yum_cache bind_mount ccache'
@@ -55,7 +55,7 @@ _comp_cmd_mock()
5555
;;
5656
esac
5757

58-
$split && return
58+
[[ $was_split ]] && return
5959

6060
if [[ $cur == -* ]]; then
6161
COMPREPLY=($(compgen -W '$(_parse_help "$1")' -- "$cur"))

completions/_repomanage

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,12 +5,12 @@
55

66
_comp_cmd_repomanage()
77
{
8-
local cur prev words cword split comp_args
8+
local cur prev words cword was_split comp_args
99
_comp_initialize -s -- "$@" || return
1010

1111
[[ $prev == -@([hk]|-help|-keep) ]] && return
1212

13-
$split && return
13+
[[ $was_split ]] && return
1414

1515
if [[ $cur == -* ]]; then
1616
COMPREPLY=($(compgen -W '$(_parse_help "$1")' -- "$cur"))

completions/_rtcwake

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55

66
_comp_cmd_rtcwake()
77
{
8-
local cur prev words cword split comp_args
8+
local cur prev words cword was_split comp_args
99
_comp_initialize -s -- "$@" || return
1010

1111
case "$prev" in
@@ -24,7 +24,7 @@ _comp_cmd_rtcwake()
2424
;;
2525
esac
2626

27-
$split && return
27+
[[ $was_split ]] && return
2828

2929
COMPREPLY=($(compgen -W '$(_parse_help "$1")' -- "$cur"))
3030
} &&

completions/_su

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ fi
1010

1111
_comp_cmd_su()
1212
{ # linux-specific completion
13-
local cur prev words cword split comp_args
13+
local cur prev words cword was_split comp_args
1414
_comp_initialize -s -- "$@" || return
1515

1616
case "$prev" in
@@ -26,7 +26,7 @@ _comp_cmd_su()
2626
;;
2727
esac
2828

29-
$split && return
29+
[[ $was_split ]] && return
3030

3131
if [[ $cur == -* ]]; then
3232
COMPREPLY=($(compgen -W '$(_parse_help "$1")' -- "$cur"))

completions/_udevadm

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55

66
_comp_cmd_udevadm()
77
{
8-
local cur prev words cword split comp_args
8+
local cur prev words cword was_split comp_args
99
_comp_initialize -s -- "$@" || return
1010

1111
local i udevcmd has_udevcmd=""
@@ -52,7 +52,7 @@ _comp_cmd_udevadm()
5252
;;
5353
esac
5454

55-
$split && return
55+
[[ $was_split ]] && return
5656

5757
if [[ ! $has_udevcmd ]]; then
5858
case $cur in

completions/_yum

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ _yum_plugins()
3939

4040
_comp_cmd_yum()
4141
{
42-
local cur prev words cword split comp_args
42+
local cur prev words cword was_split comp_args
4343
_comp_initialize -s -- "$@" || return
4444

4545
local special="" i
@@ -136,7 +136,7 @@ _comp_cmd_yum()
136136
;;
137137
esac
138138

139-
$split && return
139+
[[ $was_split ]] && return
140140

141141
if [[ $cur == -* ]]; then
142142
COMPREPLY=($(compgen -W '$(_parse_help "$1")' -- "$cur"))

completions/a2x

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
_comp_cmd_a2x()
44
{
5-
local cur prev words cword split comp_args
5+
local cur prev words cword was_split comp_args
66
_comp_initialize -s -- "$@" || return
77

88
local noargopts='!(-*|*[aDd]*)'
@@ -26,7 +26,7 @@ _comp_cmd_a2x()
2626
;;
2727
esac
2828

29-
$split && return
29+
[[ $was_split ]] && return
3030

3131
if [[ $cur == -* ]]; then
3232
COMPREPLY=($(compgen -W '$(_parse_help "$1" --help)' -- "$cur"))

0 commit comments

Comments
 (0)