Skip to content

Commit 86a7ae2

Browse files
committed
refactor(*): use _comp_compgen -P
* refactor(dot,gprof,protoc,ssh,7z): use `_comp_compgen -P` for optargs * refactor(_comp_compgen_tilde): use `_comp_compgen -P` for `~...` * refactor(curl,strings): use `_comp_compgen -P` for `@...` * refactor(tshark): use `_comp_compgen -P` for `-[oX]-...` * refactor({,u}mount,kcov,lintian): use `_comp_compgen -P` for `*,*` * refactor(upgradepkg): use `_comp_compgen -P` for `*%*` * refactor(_mount{,.linux}): use `_comp_compgen -P` for `//host/...` * refactor(xgamma): use `_comp_compgen -P` for `-display:*.*`
1 parent da7aba4 commit 86a7ae2

File tree

16 files changed

+158
-186
lines changed

16 files changed

+158
-186
lines changed

bash_completion

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1914,7 +1914,7 @@ _comp_compgen_tilde()
19141914
{
19151915
if [[ ${cur-} == \~* && $cur != */* ]]; then
19161916
# Try generate ~username completions
1917-
if _comp_compgen -c "${cur#\~}" -- -P '~' -u; then
1917+
if _comp_compgen -P '~' -- -u; then
19181918
# 2>/dev/null for direct invocation, e.g. in the
19191919
# _comp_compgen_tilde unit test
19201920
compopt -o filenames 2>/dev/null

completions/7z

Lines changed: 16 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -15,20 +15,17 @@ _comp_cmd_7z()
1515

1616
case $cur in
1717
-ao*)
18-
_comp_compgen -c "${cur:3}" -- -P"${cur:0:3}" -W 'a s t u'
18+
_comp_compgen -P "-ao" -- -W 'a s t u'
1919
return
2020
;;
2121
-?(a)[ix]*)
22-
local opt
23-
if [[ $cur == -a[ix]* ]]; then
24-
opt=${cur:0:3} cur=${cur:3}
25-
else
26-
opt=${cur:0:2} cur=${cur:2}
27-
fi
2822
if [[ $cur != *[@\!]* ]]; then
29-
_comp_compgen -- -P"$opt" -W '@ ! r@ r-@ r0@ r! r-! r0!'
30-
elif [[ $cur == ?(r@(-|0|))@* ]]; then
31-
_comp_compgen -c "${cur#*@}" -- -P"${opt}${cur%%@*}@" -f
23+
[[ $cur =~ ^-a?[ix] ]]
24+
local prefix=${BASH_REMATCH-}
25+
_comp_compgen -P "$prefix" -- -W '@ ! r@ r-@ r0@ r! r-! r0!'
26+
elif [[ $cur =~ ^-a?[ix](r|r-|r0)?@ ]]; then
27+
local prefix=${BASH_REMATCH-}
28+
_comp_compgen -P "$prefix" -- -f
3229
compopt -o filenames
3330
fi
3431
return
@@ -43,31 +40,30 @@ _comp_cmd_7z()
4340
;;
4441
-o* | -w?*)
4542
compopt -o filenames
46-
_comp_compgen -c "${cur:2}" -- -d -P"${cur:0:2}" -S/
43+
_comp_compgen -P "${cur:0:2}" -- -d -S/
4744
compopt -o nospace
4845
return
4946
;;
5047
-r?*)
51-
_comp_compgen -c "${cur:2}" -- -P"${cur:0:2}" -W '- 0'
48+
_comp_compgen -P "-r" -- -W '- 0'
5249
return
5350
;;
5451
-scs*)
55-
_comp_compgen -c "${cur:4}" -- -P"${cur:0:4}" -W 'UTF-8 WIN DOS'
52+
_comp_compgen -P "-scs" -- -W 'UTF-8 WIN DOS'
5653
return
5754
;;
5855
-ssc?*)
59-
_comp_compgen -c "${cur:4}" -- -P"${cur:0:4}" -W '-'
56+
_comp_compgen -P "-ssc" -- -W '-'
6057
return
6158
;;
6259
-t*)
6360
if [[ $mode == w ]]; then
64-
_comp_compgen -c "${cur:2}" -- -P"${cur:0:2}" -W '7z bzip2 gzip
65-
swfc tar wim xz zip'
61+
_comp_compgen -P "-t" -- -W '7z bzip2 gzip swfc tar wim xz zip'
6662
else
67-
_comp_compgen -c "${cur:2}" -- -P"${cur:0:2}" -W '7z apm arj
68-
bzip2 cab chm cpio cramfs deb dmg elf fat flv gzip hfs iso
69-
lzh lzma lzma86 macho mbr mslz mub nsis ntfs pe ppmd rar
70-
rpm squashfs swf swfc tar udf vhd wim xar xz z zip'
63+
_comp_compgen -P "-t" -- -W '7z apm arj bzip2 cab chm cpio
64+
cramfs deb dmg elf fat flv gzip hfs iso lzh lzma lzma86
65+
macho mbr mslz mub nsis ntfs pe ppmd rar rpm squashfs swf
66+
swfc tar udf vhd wim xar xz z zip'
7167
fi
7268
return
7369
;;

completions/_mount

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ _comp_cmd_mount()
4444
host=${cur#//}
4545
host=${host%%/*}
4646
if [[ $host ]]; then
47-
_comp_compgen -c "${cur#//"$host"}" split -P "//$host" -- "$(
47+
_comp_compgen -P "//$host" split -- "$(
4848
smbclient -d 0 -NL "$host" 2>/dev/null |
4949
command sed -ne '/^[[:blank:]]*Sharename/,/^$/p' |
5050
command sed -ne '3,$s|^[^A-Za-z]*\([^[:blank:]]*\).*$|/\1|p'

completions/_mount.linux

Lines changed: 90 additions & 95 deletions
Original file line numberDiff line numberDiff line change
@@ -8,24 +8,18 @@ _comp_cmd_mount()
88
local cur prev words cword comp_args
99
_comp_initialize -n =: -- "$@" || return
1010

11-
local split=""
1211
case "$prev" in
1312
-t | --types)
1413
# find /lib/modules/$(uname -r)/ -type f -path '*/fs/*.ko' -printf '%f\n' | cut -d. -f1
1514
# FIXME: no<fstype>
16-
if [[ $cur == ?*,* ]]; then
17-
prev="${cur%,*}"
18-
cur="${cur##*,}"
19-
split=set
20-
fi
21-
_comp_compgen -- -W 'auto adfs affs autofs btrfs cifs coda cramfs
22-
davfs debugfs devpts efs ext2 ext3 ext4 fuse hfs hfsplus hpfs
23-
iso9660 jffs2 jfs minix msdos ncpfs nfs nfs4 ntfs ntfs-3g proc
24-
qnx4 ramfs reiserfs romfs squashfs smbfs sysv tmpfs ubifs udf
25-
ufs umsdos usbfs vfat xfs'
26-
_comp_compgen -a fstypes
27-
[[ $split ]] && ((${#COMPREPLY[@]})) &&
28-
_comp_compgen -Rv COMPREPLY -- -P "$prev," -W '"${COMPREPLY[@]}"'
15+
[[ $cur =~ ^.+, ]]
16+
local prefix=${BASH_REMATCH-}
17+
_comp_compgen -P "$prefix" -- -W 'auto adfs affs autofs btrfs cifs
18+
coda cramfs davfs debugfs devpts efs ext2 ext3 ext4 fuse hfs
19+
hfsplus hpfs iso9660 jffs2 jfs minix msdos ncpfs nfs nfs4 ntfs
20+
ntfs-3g proc qnx4 ramfs reiserfs romfs squashfs smbfs sysv
21+
tmpfs ubifs udf ufs umsdos usbfs vfat xfs'
22+
_comp_compgen -aP "$prefix" fstypes
2923
return
3024
;;
3125
--bind | -B | --rbind | -R)
@@ -66,145 +60,146 @@ _comp_cmd_mount()
6660
# no<fstype> is not a real fstype, reset to "auto"
6761
[[ $fstype == no?* ]] && fstype=auto
6862
# split options list
69-
if [[ $cur == ?*,* ]]; then
70-
prev="${cur%,*}"
71-
cur="${cur##*,}"
72-
split=set
73-
fi
63+
[[ $cur =~ ^.+, ]]
64+
local prefix=${BASH_REMATCH-}
7465
# no completion if $cur is opt=smth
75-
[[ $cur == *=* ]] && return
66+
[[ ${cur##*,} == *=* ]] && return
7667
# mount options
77-
_comp_compgen -- -W 'loop {,a}sync {,no}atime {,no}auto
78-
{,fs,def,root}context= defaults {,no}dev {,no}diratime dirsync
79-
{,no}exec group {,no}iversion {,no}mand _netdev nofail
80-
{,no}relatime {,no}strictatime {,no}suid owner remount ro rw
81-
{,no}user users'
68+
_comp_compgen -P "$prefix" -- -W 'loop {,a}sync {,no}atime
69+
{,no}auto {,fs,def,root}context= defaults {,no}dev
70+
{,no}diratime dirsync {,no}exec group {,no}iversion {,no}mand
71+
_netdev nofail {,no}relatime {,no}strictatime {,no}suid owner
72+
remount ro rw {,no}user users'
8273
case "$fstype" in
8374
adfs | auto)
84-
_comp_compgen -a -- -W '{u,g}id= {own,oth}mask='
75+
_comp_compgen -aP "$prefix" -- -W '{u,g}id= {own,oth}mask='
8576
;;&
8677
affs | auto)
87-
_comp_compgen -a -- -W '{u,g}id= set{u,g}id= mode= protect
88-
usemp verbose prefix= volume= reserved= root= bs=
89-
{,no,usr,grp}quota'
78+
_comp_compgen -aP "$prefix" -- -W '{u,g}id= set{u,g}id=
79+
mode= protect usemp verbose prefix= volume= reserved=
80+
root= bs= {,no,usr,grp}quota'
9081
;;&
9182
btrfs | auto)
92-
_comp_compgen -a -- -W 'degraded subvol= subvolid= device=
93-
nodatasum nodatacow nobarrier max_inline= alloc_start=
94-
thread_pool= compress= compress-force= ssd noacl
95-
notreelog flushoncommit metadata_ratio=
96-
{,no}space_cache clear_cache user_subvol_rm_allowed
97-
autodefrag inode_cache'
83+
_comp_compgen -aP "$prefix" -- -W 'degraded subvol=
84+
subvolid= device= nodatasum nodatacow nobarrier
85+
max_inline= alloc_start= thread_pool= compress=
86+
compress-force= ssd noacl notreelog flushoncommit
87+
metadata_ratio= {,no}space_cache clear_cache
88+
user_subvol_rm_allowed autodefrag inode_cache'
9889
;;&
9990
cifs | auto)
100-
_comp_compgen -a -- -W 'user= password= credentials=
101-
{u,g}id= force{u,g}id port= servern= netbiosname=
102-
{file,dir}_mode= ip= domain= guest iocharset
103-
{,no}setuids {,no,dyn}perm directio {,no}mapchars
104-
{,no}intr hard soft noacl nocase sec= nobrl sfu
105-
{,no}serverino nounix nouser_xattr {r,w}size=
91+
_comp_compgen -aP "$prefix" -- -W 'user= password=
92+
credentials= {u,g}id= force{u,g}id port= servern=
93+
netbiosname= {file,dir}_mode= ip= domain= guest
94+
iocharset {,no}setuids {,no,dyn}perm directio
95+
{,no}mapchars {,no}intr hard soft noacl nocase sec=
96+
nobrl sfu {,no}serverino nounix nouser_xattr {r,w}size=
10697
rwpidforward backup{u,g}id cache='
10798
;;&
10899
davfs | auto)
109-
_comp_compgen -a -- -W 'conf= {file,dir}_mode= {u,g}id=
110-
username='
100+
_comp_compgen -aP "$prefix" -- -W 'conf= {file,dir}_mode=
101+
{u,g}id= username='
111102
;;&
112103
ext[2-4] | auto)
113-
_comp_compgen -a -- -W '{,no}acl bsddf minixdf check= debug
114-
errors= {,no}grpid {bsd,sysv}groups {,no,usr,grp}quota
115-
nobh nouid32 oldalloc orlov res{u,g}id= sb=
116-
{,no}user_xattr'
104+
_comp_compgen -aP "$prefix" -- -W '{,no}acl bsddf minixdf
105+
check= debug errors= {,no}grpid {bsd,sysv}groups
106+
{,no,usr,grp}quota nobh nouid32 oldalloc orlov
107+
res{u,g}id= sb= {,no}user_xattr'
117108
;;&
118109
ext[34] | auto)
119-
_comp_compgen -a -- -W 'journal= journal_dev= norecovery
120-
noload data= barrier= commit='
110+
_comp_compgen -aP "$prefix" -- -W 'journal= journal_dev=
111+
norecovery noload data= barrier= commit='
121112
;;&
122113
ext4 | auto)
123-
_comp_compgen -a -- -W 'journal_checksum
114+
_comp_compgen -aP "$prefix" -- -W 'journal_checksum
124115
journal_async_commit nobarrier inode_readahead= stripe=
125116
{,no}delalloc abort {max,min}_batch_time=
126117
journal_ioprio= {,no}auto_da_alloc {,no}discard nouid32
127118
resize {,no}block_validity dioread_{,no}lock
128119
max_dir_size_kb= i_version'
129120
;;&
130121
msdos | umsdos | vfat | auto)
131-
_comp_compgen -a -- -W 'blocksize= {u,g}id= {u,d,f}mask=
132-
allow_utime= check= codepage= conv= cvf_format=
133-
cvf_option= debug fat= iocharset= tz= quiet showexec
134-
sys_immutable flush usefree {,no}dots dotsOK='
122+
_comp_compgen -aP "$prefix" -- -W 'blocksize= {u,g}id=
123+
{u,d,f}mask= allow_utime= check= codepage= conv=
124+
cvf_format= cvf_option= debug fat= iocharset= tz= quiet
125+
showexec sys_immutable flush usefree {,no}dots dotsOK='
135126
;;&
136127
vfat | auto)
137-
_comp_compgen -a -- -W 'uni_xlate posix nonumtail utf8
138-
shortname='
128+
_comp_compgen -aP "$prefix" -- -W 'uni_xlate posix
129+
nonumtail utf8 shortname='
139130
;;&
140131
iso9660 | auto)
141-
_comp_compgen -a -- -W 'norock nojoliet check= {u,g}id=
142-
map= mode= unhide block= conv= cruft session= sbsector=
143-
iocharset= utf8'
132+
_comp_compgen -aP "$prefix" -- -W 'norock nojoliet check=
133+
{u,g}id= map= mode= unhide block= conv= cruft session=
134+
sbsector= iocharset= utf8'
144135
;;&
145136
jffs2 | auto)
146-
_comp_compgen -a -- -W 'compr= rp_size='
137+
_comp_compgen -aP "$prefix" -- -W 'compr= rp_size='
147138
;;&
148139
jfs | auto)
149-
_comp_compgen -a -- -W 'iocharset= resize= {,no}integrity
150-
errors= {,no,usr,grp}quota'
140+
_comp_compgen -aP "$prefix" -- -W 'iocharset= resize=
141+
{,no}integrity errors= {,no,usr,grp}quota'
151142
;;&
152143
nfs | nfs4 | auto)
153-
_comp_compgen -a -- -W 'soft hard timeo= retrans= {r,w}size=
154-
{,no}ac acreg{min,max}= acdir{min,max}= actimeo= bg fg
155-
retry= sec= {,no}sharecache {,no}resvport lookupcache=
156-
proto= port= {,no}intr {,no}cto {,nfs}vers='
144+
_comp_compgen -aP "$prefix" -- -W 'soft hard timeo=
145+
retrans= {r,w}size= {,no}ac acreg{min,max}=
146+
acdir{min,max}= actimeo= bg fg retry= sec=
147+
{,no}sharecache {,no}resvport lookupcache= proto= port=
148+
{,no}intr {,no}cto {,nfs}vers='
157149
;;&
158150
nfs | auto)
159-
_comp_compgen -a -- -W 'udp tcp rdma mount{port,proto,host}=
160-
mountvers= namlen={,no}lock {,no}acl {,no}rdirplus
161-
{,no}fsc'
151+
_comp_compgen -aP "$prefix" -- -W 'udp tcp rdma
152+
mount{port,proto,host}= mountvers= namlen={,no}lock
153+
{,no}acl {,no}rdirplus {,no}fsc'
162154
;;&
163155
nfs4 | auto)
164-
_comp_compgen -a -- -W 'clientaddr= {,no}migration'
156+
_comp_compgen -aP "$prefix" -- -W 'clientaddr=
157+
{,no}migration'
165158
;;&
166159
ntfs-3g)
167-
_comp_compgen -a -- -W '{u,g}id= {u,f,d}mask= usermapping=
168-
permissions inherit locale= force {,no}recover
169-
ignore_case remove_hiberfile show_sys_files
170-
hide_{hid,dot}_files windows_names allow_other
171-
max_read= silent no_def_opts streams_interface=
172-
user_xattr efs_raw {,no}compression debug no_detach'
160+
_comp_compgen -aP "$prefix" -- -W '{u,g}id= {u,f,d}mask=
161+
usermapping= permissions inherit locale= force
162+
{,no}recover ignore_case remove_hiberfile
163+
show_sys_files hide_{hid,dot}_files windows_names
164+
allow_other max_read= silent no_def_opts
165+
streams_interface= user_xattr efs_raw {,no}compression
166+
debug no_detach'
173167
;;&
174168
proc | auto)
175-
_comp_compgen -a -- -W '{u,g}id='
169+
_comp_compgen -aP "$prefix" -- -W '{u,g}id='
176170
;;&
177171
reiserfs | auto)
178-
_comp_compgen -a -- -W 'conv hash=
172+
_comp_compgen -aP "$prefix" -- -W 'conv hash=
179173
{,no_un}hashed_relocation noborder nolog notail
180174
replayonly resize= user_xattr acl barrier='
181175
;;&
182176
tmpfs | auto)
183-
_comp_compgen -a -- -W 'size= nr_blocks= nr_inodes= mode=
184-
{u,g}id= mpol='
177+
_comp_compgen -aP "$prefix" -- -W 'size= nr_blocks=
178+
nr_inodes= mode= {u,g}id= mpol='
185179
;;&
186180
udf | auto)
187-
_comp_compgen -a -- -W '{u,g}id= umask= unhide undelete
188-
nostrict iocharset bs= novrs session= anchor= volume=
189-
partition= lastblock= fileset= rootdir='
181+
_comp_compgen -aP "$prefix" -- -W '{u,g}id= umask= unhide
182+
undelete nostrict iocharset bs= novrs session= anchor=
183+
volume= partition= lastblock= fileset= rootdir='
190184
;;&
191185
usbfs | auto)
192-
_comp_compgen -a -- -W 'dev{u,g}id= devmode= bus{u,g}id=
193-
busmode= list{u,g}id= listmode='
186+
_comp_compgen -aP "$prefix" -- -W 'dev{u,g}id= devmode=
187+
bus{u,g}id= busmode= list{u,g}id= listmode='
194188
;;&
195189
xfs | auto)
196-
_comp_compgen -a -- -W 'allocsize= {,no}attr2 barrier dmapi
197-
{,no}grpid {bsd,sysv}groups ihashsize= {,no}ikeep
198-
inode{32,64} {,no}largeio logbufs= logbsize= logdev=
199-
rtdev= mtpt= noalign norecovery nouuid osyncisosync
200-
{u,g,p}qnoenforce {,u,usr,g,grp,p,prj}quota sunit=
201-
swidth= swalloc'
190+
_comp_compgen -aP "$prefix" -- -W 'allocsize= {,no}attr2
191+
barrier dmapi {,no}grpid {bsd,sysv}groups ihashsize=
192+
{,no}ikeep inode{32,64} {,no}largeio logbufs= logbsize=
193+
logdev= rtdev= mtpt= noalign norecovery nouuid
194+
osyncisosync {u,g,p}qnoenforce
195+
{,u,usr,g,grp,p,prj}quota sunit= swidth= swalloc'
202196
;;&
203197
esac
204198
# COMP_WORDBREAKS is a real pain in the ass
205-
prev="${prev##*["$COMP_WORDBREAKS"]}"
206-
[[ $split ]] && ((${COMPREPLY[@]})) &&
207-
_comp_compgen -Rv COMPREPLY -- -P "$prev," -W '"${COMPREPLY[@]}"'
199+
if ((${#COMPREPLY[@]})) && [[ $prefix == *["$COMP_WORDBREAKS"]* ]]; then
200+
local tmp=${prefix%["$COMP_WORDBREAKS"]*}
201+
COMPREPLY=("${COMPREPLY[@]#"$tmp"?}")
202+
fi
208203
[[ ${COMPREPLY-} == *= ]] && compopt -o nospace
209204
return
210205
;;
@@ -236,7 +231,7 @@ _comp_cmd_mount()
236231
host=${cur#//}
237232
host=${host%%/*}
238233
if [[ $host ]]; then
239-
_comp_compgen -c "${cur#//"$host"}" split -P "//$host" -- "$(
234+
_comp_compgen -P "//$host" split -- "$(
240235
smbclient -d 0 -NL "$host" 2>/dev/null |
241236
command sed -ne '/^[[:blank:]]*Sharename/,/^$/p' |
242237
command sed -ne '3,$s|^[^A-Za-z]*\([^[:blank:]]*\).*$|/\1|p'

completions/_umount.linux

Lines changed: 8 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -98,20 +98,14 @@ _comp_cmd_umount()
9898
case "$prev" in
9999
-t)
100100
# FIXME: no<fstype>
101-
local split=""
102-
if [[ $cur == ?*,* ]]; then
103-
prev="${cur%,*}"
104-
cur="${cur##*,}"
105-
split=set
106-
fi
107-
_comp_compgen -- -W 'adfs affs autofs btrfs cifs coda cramfs
108-
debugfs devpts efs ext2 ext3 ext4 fuse hfs hfsplus hpfs iso9660
109-
jfs minix msdos ncpfs nfs nfs4 ntfs ntfs-3g proc qnx4 ramfs
110-
reiserfs romfs squashfs smbfs sysv tmpfs ubifs udf ufs umsdos
111-
usbfs vfat xfs'
112-
_comp_compgen -a fstypes
113-
[[ $split ]] && ((${#COMPREPLY[@]})) &&
114-
_comp_compgen -Rv COMPREPLY -- -P "$prev," -W '"${COMPREPLY[@]}"'
101+
[[ $cur =~ ^.+, ]]
102+
local prefix=${BASH_REMATCH-}
103+
_comp_compgen -P "$prefix" -- -W 'adfs affs autofs btrfs cifs coda
104+
cramfs debugfs devpts efs ext2 ext3 ext4 fuse hfs hfsplus hpfs
105+
iso9660 jfs minix msdos ncpfs nfs nfs4 ntfs ntfs-3g proc qnx4
106+
ramfs reiserfs romfs squashfs smbfs sysv tmpfs ubifs udf ufs
107+
umsdos usbfs vfat xfs'
108+
_comp_compgen -aP "$prefix" fstypes
115109
return
116110
;;
117111
-O)

0 commit comments

Comments
 (0)