Skip to content

Commit 158b8ba

Browse files
committed
fix: use _comp_compgen_split to split and filter words
1 parent b63d25a commit 158b8ba

File tree

8 files changed

+26
-50
lines changed

8 files changed

+26
-50
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/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/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/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
@@ -51,10 +51,9 @@ _comp_cmd_povray()
5151
cur="${povcur#*\[}"
5252
pfx="${povcur%\["$cur"}" # prefix == filename
5353
[[ -f $pfx && -r $pfx ]] || return
54-
COMPREPLY=($(command sed -ne \
55-
's/^[[:space:]]*\[\('"$cur"'[^]]*\]\).*$/\1/p' -- "$pfx"))
56-
# to prevent [bar] expand to nothing. can be done more easily?
57-
((${#COMPREPLY[@]})) &&
54+
_comp_compgen_split -l -- "$(command sed -ne \
55+
's/^[[:space:]]*\[\([^]]*\]\).*$/\1/p' -- "$pfx")" &&
56+
# to prevent [bar] expand to nothing. can be done more easily?
5857
_comp_compgen -Rv COMPREPLY -- -P "${pfx}[" -W '"${COMPREPLY[@]}"'
5958
return
6059
;;

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/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)