Skip to content

Commit 8030f21

Browse files
authored
Merge pull request #1087 from akinomyoga/_comp_split
fix: refactor array assignments with manual `cur` filtering
2 parents 18fac2b + 509e642 commit 8030f21

File tree

14 files changed

+54
-71
lines changed

14 files changed

+54
-71
lines changed

completions/_slackpkg

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -81,13 +81,15 @@ _comp_cmd_slackpkg()
8181
_comp_compgen_filedir
8282
_comp_compgen -a -- -W 'a ap d e f k kde kdei l n t tcl x xap xfce
8383
y'
84-
COMPREPLY+=($(cut -f 6 -d\ "${WORKDIR}/pkglist" 2>/dev/null |
85-
command grep "^$cur"))
84+
_comp_compgen -a split -l -- "$(
85+
cut -f 6 -d\ "${WORKDIR}/pkglist" 2>/dev/null
86+
)"
8687
return
8788
;;
8889
info)
89-
COMPREPLY=($(cut -f 6 -d\ "${WORKDIR}/pkglist" 2>/dev/null |
90-
command grep "^$cur"))
90+
_comp_compgen_split "$(
91+
cut -f 6 -d\ "${WORKDIR}/pkglist" 2>/dev/null
92+
)"
9193
return
9294
;;
9395
update)

completions/_yum

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,13 +8,13 @@ _comp_cmd_yum__list()
88
if [[ $1 == all ]]; then
99
# Try to strip in between headings like "Available Packages"
1010
# This will obviously only work for English :P
11-
COMPREPLY=($(yum -d 0 -C list "$1" "$cur*" 2>/dev/null |
11+
_comp_split COMPREPLY "$(yum -d 0 -C list "$1" "$cur*" 2>/dev/null |
1212
command sed -ne '/^Available /d' -e '/^Installed /d' \
13-
-e '/^Updated /d' -e 's/[[:space:]].*//p'))
13+
-e '/^Updated /d' -e 's/[[:space:]].*//p')"
1414
else
1515
# Drop first line (e.g. "Updated Packages")
16-
COMPREPLY=($(yum -d 0 -C list "$1" "$cur*" 2>/dev/null |
17-
command sed -ne 1d -e 's/[[:space:]].*//p'))
16+
_comp_split COMPREPLY "$(yum -d 0 -C list "$1" "$cur*" 2>/dev/null |
17+
command sed -ne 1d -e 's/[[:space:]].*//p')"
1818
fi
1919
}
2020

completions/aptitude

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -52,9 +52,8 @@ _comp_cmd_aptitude()
5252
return
5353
;;
5454
--target-release | --default-release | -${noargopts}t)
55-
COMPREPLY=($(apt-cache policy |
56-
command grep "release.o=Debian,a=$cur" |
57-
command sed -e "s/.*a=\([_[:alnum:]]*\).*/\1/" | uniq 2>/dev/null))
55+
_comp_compgen_split -l -- "$(apt-cache policy |
56+
command sed -ne 's/.*release.o=Debian,a=\([_[:alnum:]]*\).*/\1/p')"
5857
return
5958
;;
6059
esac

completions/cpan2dist

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,9 +27,9 @@ _comp_cmd_cpan2dist()
2727
[[ -d $dir && -r "$dir/02packages.details.txt.gz" ]] &&
2828
packagelist="$dir/02packages.details.txt.gz"
2929
done
30-
[[ $packagelist ]] && COMPREPLY=($(zgrep "^${cur//-/::}" \
30+
[[ $packagelist ]] && _comp_split COMPREPLY "$(zgrep "^${cur//-/::}" \
3131
"$packagelist" 2>/dev/null | _comp_awk '{print $1}' |
32-
command sed -e 's/::/-/g'))
32+
command sed -e 's/::/-/g')"
3333
fi
3434
} &&
3535
complete -F _comp_cmd_cpan2dist -o default cpan2dist

completions/isql

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,9 @@ _comp_cmd_isql()
77
_comp_initialize -- "$@" || return
88

99
[[ -f ${ODBCINI-} ]] &&
10-
COMPREPLY=($(command grep "\[$cur" "$ODBCINI" | tr -d \[\]))
10+
_comp_compgen_split -l -- "$(
11+
command sed -n 's/\]//g;s/^\[//gp' "$ODBCINI"
12+
)"
1113
} &&
1214
complete -F _comp_cmd_isql isql
1315

completions/make

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -154,11 +154,10 @@ _comp_cmd_make()
154154
# mode=-d # display-only mode
155155
# fi
156156

157-
local IFS=$' \t\n'
158-
COMPREPLY=($(LC_ALL=C \
157+
_comp_split COMPREPLY "$(LC_ALL=C \
159158
$1 -npq __BASH_MAKE_COMPLETION__=1 \
160159
${makef+"${makef[@]}"} "${makef_dir[@]}" .DEFAULT 2>/dev/null |
161-
_comp_cmd_make__extract_targets "$mode" "$cur"))
160+
_comp_cmd_make__extract_targets "$mode" "$cur")"
162161

163162
_comp_cmd_make__truncate_non_unique_paths
164163

completions/postcat

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -22,13 +22,8 @@ _comp_cmd_postcat()
2222
[[ $idx == -q ]] && qfile=set && break
2323
done
2424
if [[ $qfile ]]; then
25-
local len=${#cur} pval
26-
for pval in $(mailq 2>/dev/null |
27-
command sed -e '1d; $d; /^[^0-9A-Z]/d; /^$/d; s/[* !].*$//'); do
28-
if [[ $cur == "${pval:0:len}" ]]; then
29-
COMPREPLY+=("$pval")
30-
fi
31-
done
25+
_comp_compgen_split -- "$(mailq 2>/dev/null |
26+
command sed -e '1d; $d; /^[^0-9A-Z]/d; /^$/d; s/[* !].*$//')"
3227
return
3328
fi
3429

completions/postsuper

Lines changed: 6 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -5,42 +5,25 @@ _comp_cmd_postsuper()
55
local cur prev words cword comp_args
66
_comp_initialize -- "$@" || return
77

8-
local pval len
9-
108
case $prev in
119
-c)
1210
_comp_compgen_filedir -d
1311
return
1412
;;
1513
-[dr])
16-
len=${#cur}
17-
for pval in ALL $(mailq 2>/dev/null |
18-
command sed -e '1d; $d; /^[^0-9A-Z]/d; /^$/d; s/[* !].*$//'); do
19-
if [[ $cur == "${pval:0:len}" ]]; then
20-
COMPREPLY+=($pval)
21-
fi
22-
done
14+
_comp_compgen_split -- "ALL $(mailq 2>/dev/null |
15+
command sed -e '1d; $d; /^[^0-9A-Z]/d; /^$/d; s/[* !].*$//')"
2316
return
2417
;;
2518
-h)
26-
len=${#cur}
27-
for pval in ALL $(mailq 2>/dev/null |
19+
_comp_compgen_split -- "ALL $(mailq 2>/dev/null |
2820
command sed \
29-
-e '1d; $d; /^[^0-9A-Z]/d; /^$/d; s/[* ].*$//; /!$/d'); do
30-
if [[ $cur == "${pval:0:len}" ]]; then
31-
COMPREPLY+=($pval)
32-
fi
33-
done
21+
-e '1d; $d; /^[^0-9A-Z]/d; /^$/d; s/[* ].*$//; /!$/d')"
3422
return
3523
;;
3624
-H)
37-
len=${#cur}
38-
for pval in ALL $(mailq 2>/dev/null | command sed -e \
39-
'1d; $d; /^[^0-9A-Z]/d; /^$/d; /^[0-9A-Z]*[* ]/d; s/!.*$//'); do
40-
if [[ $cur == "${pval:0:len}" ]]; then
41-
COMPREPLY+=($pval)
42-
fi
43-
done
25+
_comp_compgen_split -- "ALL $(mailq 2>/dev/null | command sed \
26+
-e '1d; $d; /^[^0-9A-Z]/d; /^$/d; /^[0-9A-Z]*[* ]/d; s/!.*$//')"
4427
return
4528
;;
4629
esac

completions/povray

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -48,10 +48,9 @@ _comp_cmd_povray()
4848
cur="${povcur#*\[}"
4949
pfx="${povcur%\["$cur"}" # prefix == filename
5050
[[ -f $pfx && -r $pfx ]] || return
51-
COMPREPLY=($(command sed -ne \
52-
's/^[[:space:]]*\[\('"$cur"'[^]]*\]\).*$/\1/p' -- "$pfx"))
53-
# to prevent [bar] expand to nothing. can be done more easily?
54-
((${#COMPREPLY[@]})) &&
51+
_comp_compgen_split -l -- "$(command sed -ne \
52+
's/^[[:space:]]*\[\([^]]*\]\).*$/\1/p' -- "$pfx")" &&
53+
# to prevent [bar] expand to nothing. can be done more easily?
5554
_comp_compgen -Rv COMPREPLY -- -P "${pfx}[" -W '"${COMPREPLY[@]}"'
5655
return
5756
;;

completions/sbopkg

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -61,10 +61,8 @@ _comp_cmd_sbopkg()
6161
local file=${REPO_ROOT-}/${REPO_NAME-}/${REPO_BRANCH-}/SLACKBUILDS.TXT
6262
[[ -f $file && -r $file ]] || return
6363

64-
COMPREPLY=($(
65-
command sed -ne "/^SLACKBUILD NAME: $cur/{s/^SLACKBUILD NAME: //;p;}" \
66-
"$file"
67-
))
64+
_comp_compgen_split -l -- "$(command sed -ne "s/^SLACKBUILD NAME: //p" \
65+
"$file")"
6866
_comp_compgen -aC "$QUEUEDIR" -- -f -X "!*.sqf"
6967
} &&
7068
complete -F _comp_cmd_sbopkg sbopkg

completions/slapt-get

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -60,13 +60,17 @@ _comp_cmd_slapt_get()
6060
# slapt-get will fail to search for "^name-version"
6161
# it can search for names only
6262
local name=${cur%%-*}
63-
COMPREPLY=($(LC_ALL=C "$1" -c "$config" --search "^$name" \
64-
2>/dev/null | LC_ALL=C command sed -ne "/^$cur/{s/ .*$//;p;}"))
63+
_comp_compgen_split -l -- "$(
64+
LC_ALL=C "$1" -c "$config" --search "^$name" 2>/dev/null |
65+
LC_ALL=C command sed -ne "/^$cur/{s/ .*$//;p;}"
66+
)"
6567
return
6668
;;
6769
avl) # --install|-i|
68-
COMPREPLY=($(LC_ALL=C "$1" -c "$config" --available \
69-
2>/dev/null | LC_ALL=C command sed -ne "/^$cur/{s/ .*$//;p;}"))
70+
_comp_compgen_split -l -- "$(
71+
LC_ALL=C "$1" -c "$config" --available 2>/dev/null |
72+
LC_ALL=C command sed -ne "/^$cur/{s/ .*$//;p;}"
73+
)"
7074
return
7175
;;
7276
ins) # --remove|--filelist

completions/slapt-src

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -56,12 +56,17 @@ _comp_cmd_slapt_src()
5656

5757
if [[ $cur == *:* ]]; then
5858
local name=${cur%:*}
59-
COMPREPLY=($(LC_ALL=C "$1" --config "$config" --search "^$name" \
60-
2>/dev/null | LC_ALL=C command sed -ne \
61-
"/^$cur/{s/^$name:\([^ ]*\) .*$/\1/;p;}"))
59+
_comp_compgen_split -l -- "$(
60+
LC_ALL=C
61+
"$1" --config "$config" --search "^$name" 2>/dev/null |
62+
command sed -ne "/^$cur/{s/^$name:\([^ ]*\) .*$/\1/;p;}"
63+
)"
6264
else
63-
COMPREPLY=($(LC_ALL=C "$1" --config "$config" --search "^$cur" \
64-
2>/dev/null | LC_ALL=C command sed -ne "/^$cur/{s/ .*$//;p;}"))
65+
_comp_compgen_split -l -- "$(
66+
LC_ALL=C
67+
"$1" --config "$config" --search "^$cur" 2>/dev/null |
68+
command sed -ne "/^$cur/{s/ .*$//;p;}"
69+
)"
6570
fi
6671
} &&
6772
complete -F _comp_cmd_slapt_src slapt-src

completions/vncviewer

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -83,14 +83,13 @@ _comp_cmd_xvnc4viewer()
8383
WMDecorationWidth ZlibLevel)
8484
[[ $cur == --* ]] && dash=-- || dash=-
8585

86-
local IFS=$' \t\n'
87-
COMPREPLY=($(
86+
_comp_split COMPREPLY "$(
8887
shopt -s nocasematch
8988
local option
9089
for option in "${options[@]}"; do
9190
[[ $dash$option == "$cur"* ]] && printf '%s\n' "$dash$option"
9291
done
93-
))
92+
)"
9493
else
9594
_comp_compgen_known_hosts -- "$cur"
9695
fi

completions/wvdial

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -33,10 +33,8 @@ _comp_cmd_wvdial()
3333
done
3434
# parse config files for sections and
3535
# remove default section
36-
COMPREPLY=($(
37-
command sed -ne "s|^\[Dialer \($cur.*\)\]$|\1|p" "$config" \
38-
2>/dev/null | command grep -v '^Defaults$'
39-
))
36+
_comp_compgen_split -l -X 'Defaults' -- "$(command sed -ne \
37+
's/^\[Dialer \(.*\)\]$/\1/p' "$config" 2>/dev/null)"
4038
# escape spaces
4139
COMPREPLY=("${COMPREPLY[@]// /\\ }")
4240
;;

0 commit comments

Comments
 (0)