Skip to content

fix: use _comp_compgen for multiline COMPREPLY=($(compgen ...)) #970

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
May 9, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 10 additions & 14 deletions completions/7z
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,7 @@ _comp_cmd_7z()
opt=${cur:0:2} cur=${cur:2}
fi
if [[ $cur != *[@\!]* ]]; then
COMPREPLY=($(compgen -P"$opt" -W '@ ! r@ r-@ r0@ r! r-! r0!' \
-- "$cur"))
_comp_compgen -- -P"$opt" -W '@ ! r@ r-@ r0@ r! r-! r0!'
elif [[ $cur == ?(r@(-|0|))@* ]]; then
_comp_compgen -c "${cur#*@}" -- -P"${opt}${cur%%@*}@" -f
compopt -o filenames
Expand All @@ -53,8 +52,7 @@ _comp_cmd_7z()
return
;;
-scs*)
COMPREPLY=($(compgen -P"${cur:0:4}" -W 'UTF-8 WIN DOS' \
-- "${cur:4}"))
_comp_compgen -c "${cur:4}" -- -P"${cur:0:4}" -W 'UTF-8 WIN DOS'
return
;;
-ssc?*)
Expand All @@ -63,14 +61,13 @@ _comp_cmd_7z()
;;
-t*)
if [[ $mode == w ]]; then
COMPREPLY=($(compgen -P"${cur:0:2}" -W '7z bzip2 gzip swfc
tar wim xz zip' -- "${cur:2}"))
_comp_compgen -c "${cur:2}" -- -P"${cur:0:2}" -W '7z bzip2 gzip
swfc tar wim xz zip'
else
COMPREPLY=($(compgen -P"${cur:0:2}" -W '7z apm arj bzip2 cab
chm cpio cramfs deb dmg elf fat flv gzip hfs iso lzh lzma
lzma86 macho mbr mslz mub nsis ntfs pe ppmd rar rpm
squashfs swf swfc tar udf vhd wim xar xz z zip' \
-- "${cur:2}"))
_comp_compgen -c "${cur:2}" -- -P"${cur:0:2}" -W '7z apm arj
bzip2 cab chm cpio cramfs deb dmg elf fat flv gzip hfs iso
lzh lzma lzma86 macho mbr mslz mub nsis ntfs pe ppmd rar
rpm squashfs swf swfc tar udf vhd wim xar xz z zip'
fi
return
;;
Expand All @@ -80,9 +77,8 @@ _comp_cmd_7z()
esac

if [[ $cur == -* ]]; then
COMPREPLY=($(compgen -W '-ai -an -ao -ax -bd -i -m{x,s,f,he,hc,mt}=
-o -p -r -scs -sfx -si -slp -slt -so -ssc -t -u -v -w -x -y' \
-- "$cur"))
_comp_compgen -- -W '-ai -an -ao -ax -bd -i -m{x,s,f,he,hc,mt}=
-o -p -r -scs -sfx -si -slp -slt -so -ssc -t -u -v -w -x -y'
[[ ${COMPREPLY-} == -@(an|bd|sfx|si|slt|so|ssc|[rwy]) ]] ||
compopt -o nospace
return
Expand Down
3 changes: 1 addition & 2 deletions completions/_dmesg
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,7 @@ _comp_cmd_dmesg()
return
;;
-f | --facility)
COMPREPLY=($(compgen -W 'kern user mail daemon auth syslog lpr
news' -- "$cur"))
_comp_compgen -- -W 'kern user mail daemon auth syslog lpr news'
return
;;
-l | --level | -n | --console-level)
Expand Down
160 changes: 81 additions & 79 deletions completions/_mount.linux
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,11 @@ _comp_cmd_mount()
cur="${cur##*,}"
split=set
fi
COMPREPLY=($(compgen -W 'auto adfs affs autofs btrfs cifs coda
cramfs davfs debugfs devpts efs ext2 ext3 ext4 fuse hfs hfsplus
hpfs iso9660 jffs2 jfs minix msdos ncpfs nfs nfs4 ntfs ntfs-3g
proc qnx4 ramfs reiserfs romfs squashfs smbfs sysv tmpfs ubifs
udf ufs umsdos usbfs vfat xfs' -- "$cur"))
_comp_compgen -- -W 'auto adfs affs autofs btrfs cifs coda cramfs
davfs debugfs devpts efs ext2 ext3 ext4 fuse hfs hfsplus hpfs
iso9660 jffs2 jfs minix msdos ncpfs nfs nfs4 ntfs ntfs-3g proc
qnx4 ramfs reiserfs romfs squashfs smbfs sysv tmpfs ubifs udf
ufs umsdos usbfs vfat xfs'
_fstypes
[[ $split ]] && COMPREPLY=(${COMPREPLY[@]/#/$prev,})
return
Expand Down Expand Up @@ -79,129 +79,131 @@ _comp_cmd_mount()
# no completion if $cur is opt=smth
[[ $cur == *=* ]] && return
# mount options
COMPREPLY=($(compgen -W 'loop {,a}sync {,no}atime {,no}auto
_comp_compgen -- -W 'loop {,a}sync {,no}atime {,no}auto
{,fs,def,root}context= defaults {,no}dev {,no}diratime dirsync
{,no}exec group {,no}iversion {,no}mand _netdev nofail
{,no}relatime {,no}strictatime {,no}suid owner remount ro rw
{,no}user users' -- "$cur"))
{,no}user users'
case "$fstype" in
adfs | auto)
_comp_compgen -a -- -W '{u,g}id= {own,oth}mask='
;;&
affs | auto)
COMPREPLY+=($(compgen -W '{u,g}id= set{u,g}id= mode= protect
usemp verbose prefix= volume= reserved= root= bs=
{,no,usr,grp}quota' -- "$cur"))
_comp_compgen -a -- -W '{u,g}id= set{u,g}id= mode= protect
usemp verbose prefix= volume= reserved= root= bs=
{,no,usr,grp}quota'
;;&
btrfs | auto)
COMPREPLY+=($(compgen -W 'degraded subvol= subvolid= device=
nodatasum nodatacow nobarrier max_inline= alloc_start=
thread_pool= compress= compress-force= ssd noacl notreelog
flushoncommit metadata_ratio= {,no}space_cache clear_cache
user_subvol_rm_allowed autodefrag inode_cache' -- "$cur"))
_comp_compgen -a -- -W 'degraded subvol= subvolid= device=
nodatasum nodatacow nobarrier max_inline= alloc_start=
thread_pool= compress= compress-force= ssd noacl
notreelog flushoncommit metadata_ratio=
{,no}space_cache clear_cache user_subvol_rm_allowed
autodefrag inode_cache'
;;&
cifs | auto)
COMPREPLY+=($(compgen -W 'user= password= credentials= {u,g}id=
force{u,g}id port= servern= netbiosname= {file,dir}_mode=
ip= domain= guest iocharset {,no}setuids {,no,dyn}perm
directio {,no}mapchars {,no}intr hard soft noacl nocase sec=
nobrl sfu {,no}serverino nounix nouser_xattr {r,w}size=
rwpidforward backup{u,g}id cache=' -- "$cur"))
_comp_compgen -a -- -W 'user= password= credentials=
{u,g}id= force{u,g}id port= servern= netbiosname=
{file,dir}_mode= ip= domain= guest iocharset
{,no}setuids {,no,dyn}perm directio {,no}mapchars
{,no}intr hard soft noacl nocase sec= nobrl sfu
{,no}serverino nounix nouser_xattr {r,w}size=
rwpidforward backup{u,g}id cache='
;;&
davfs | auto)
COMPREPLY+=($(compgen -W 'conf= {file,dir}_mode= {u,g}id=
username=' -- "$cur"))
_comp_compgen -a -- -W 'conf= {file,dir}_mode= {u,g}id=
username='
;;&
ext[2-4] | auto)
COMPREPLY+=($(compgen -W '{,no}acl bsddf minixdf check= debug
errors= {,no}grpid {bsd,sysv}groups {,no,usr,grp}quota
nobh nouid32 oldalloc orlov res{u,g}id= sb=
{,no}user_xattr' -- "$cur"))
_comp_compgen -a -- -W '{,no}acl bsddf minixdf check= debug
errors= {,no}grpid {bsd,sysv}groups {,no,usr,grp}quota
nobh nouid32 oldalloc orlov res{u,g}id= sb=
{,no}user_xattr'
;;&
ext[34] | auto)
COMPREPLY+=($(compgen -W 'journal= journal_dev= norecovery
noload data= barrier= commit=' -- "$cur"))
_comp_compgen -a -- -W 'journal= journal_dev= norecovery
noload data= barrier= commit='
;;&
ext4 | auto)
COMPREPLY+=($(compgen -W 'journal_checksum journal_async_commit
nobarrier inode_readahead= stripe= {,no}delalloc abort
{max,min}_batch_time= journal_ioprio= {,no}auto_da_alloc
{,no}discard nouid32 resize {,no}block_validity
dioread_{,no}lock max_dir_size_kb= i_version' -- "$cur"))
_comp_compgen -a -- -W 'journal_checksum
journal_async_commit nobarrier inode_readahead= stripe=
{,no}delalloc abort {max,min}_batch_time=
journal_ioprio= {,no}auto_da_alloc {,no}discard nouid32
resize {,no}block_validity dioread_{,no}lock
max_dir_size_kb= i_version'
;;&
msdos | umsdos | vfat | auto)
COMPREPLY+=($(compgen -W 'blocksize= {u,g}id= {u,d,f}mask=
allow_utime= check= codepage= conv= cvf_format= cvf_option=
debug fat= iocharset= tz= quiet showexec sys_immutable flush
usefree {,no}dots dotsOK=' -- "$cur"))
_comp_compgen -a -- -W 'blocksize= {u,g}id= {u,d,f}mask=
allow_utime= check= codepage= conv= cvf_format=
cvf_option= debug fat= iocharset= tz= quiet showexec
sys_immutable flush usefree {,no}dots dotsOK='
;;&
vfat | auto)
COMPREPLY+=($(compgen -W 'uni_xlate posix nonumtail utf8
shortname=' -- "$cur"))
_comp_compgen -a -- -W 'uni_xlate posix nonumtail utf8
shortname='
;;&
iso9660 | auto)
COMPREPLY+=($(compgen -W 'norock nojoliet check= {u,g}id= map=
mode= unhide block= conv= cruft session= sbsector=
iocharset= utf8' -- "$cur"))
_comp_compgen -a -- -W 'norock nojoliet check= {u,g}id=
map= mode= unhide block= conv= cruft session= sbsector=
iocharset= utf8'
;;&
jffs2 | auto)
_comp_compgen -a -- -W 'compr= rp_size='
;;&
jfs | auto)
COMPREPLY+=($(compgen -W 'iocharset= resize= {,no}integrity
errors= {,no,usr,grp}quota' -- "$cur"))
_comp_compgen -a -- -W 'iocharset= resize= {,no}integrity
errors= {,no,usr,grp}quota'
;;&
nfs | nfs4 | auto)
COMPREPLY+=($(compgen -W 'soft hard timeo= retrans= {r,w}size=
{,no}ac acreg{min,max}= acdir{min,max}= actimeo= bg fg
retry= sec= {,no}sharecache {,no}resvport lookupcache=
proto= port= {,no}intr {,no}cto {,nfs}vers= ' -- "$cur"))
_comp_compgen -a -- -W 'soft hard timeo= retrans= {r,w}size=
{,no}ac acreg{min,max}= acdir{min,max}= actimeo= bg fg
retry= sec= {,no}sharecache {,no}resvport lookupcache=
proto= port= {,no}intr {,no}cto {,nfs}vers='
;;&
nfs | auto)
COMPREPLY+=($(compgen -W 'udp tcp rdma mount{port,proto,host}=
mountvers= namlen={,no}lock {,no}acl {,no}rdirplus
{,no}fsc' -- "$cur"))
_comp_compgen -a -- -W 'udp tcp rdma mount{port,proto,host}=
mountvers= namlen={,no}lock {,no}acl {,no}rdirplus
{,no}fsc'
;;&
nfs4 | auto)
COMPREPLY+=($(compgen -W 'clientaddr= {,no}migration' \
-- "$cur"))
_comp_compgen -a -- -W 'clientaddr= {,no}migration'
;;&
ntfs-3g)
COMPREPLY+=($(compgen -W '{u,g}id= {u,f,d}mask= usermapping=
permissions inherit locale= force {,no}recover
ignore_case remove_hiberfile show_sys_files
hide_{hid,dot}_files windows_names allow_other max_read=
silent no_def_opts streams_interface= user_xattr efs_raw
{,no}compression debug no_detach' -- "$cur"))
_comp_compgen -a -- -W '{u,g}id= {u,f,d}mask= usermapping=
permissions inherit locale= force {,no}recover
ignore_case remove_hiberfile show_sys_files
hide_{hid,dot}_files windows_names allow_other
max_read= silent no_def_opts streams_interface=
user_xattr efs_raw {,no}compression debug no_detach'
;;&
proc | auto)
_comp_compgen -a -- -W '{u,g}id='
;;&
reiserfs | auto)
COMPREPLY+=($(compgen -W 'conv hash= {,no_un}hashed_relocation
noborder nolog notail replayonly resize= user_xattr acl
barrier=' -- "$cur"))
_comp_compgen -a -- -W 'conv hash=
{,no_un}hashed_relocation noborder nolog notail
replayonly resize= user_xattr acl barrier='
;;&
tmpfs | auto)
COMPREPLY+=($(compgen -W 'size= nr_blocks= nr_inodes= mode=
{u,g}id= mpol=' -- "$cur"))
_comp_compgen -a -- -W 'size= nr_blocks= nr_inodes= mode=
{u,g}id= mpol='
;;&
udf | auto)
COMPREPLY+=($(compgen -W '{u,g}id= umask= unhide undelete
nostrict iocharset bs= novrs session= anchor= volume=
partition= lastblock= fileset= rootdir=' -- "$cur"))
_comp_compgen -a -- -W '{u,g}id= umask= unhide undelete
nostrict iocharset bs= novrs session= anchor= volume=
partition= lastblock= fileset= rootdir='
;;&
usbfs | auto)
COMPREPLY+=($(compgen -W 'dev{u,g}id= devmode= bus{u,g}id=
busmode= list{u,g}id= listmode=' -- "$cur"))
_comp_compgen -a -- -W 'dev{u,g}id= devmode= bus{u,g}id=
busmode= list{u,g}id= listmode='
;;&
xfs | auto)
COMPREPLY+=($(compgen -W 'allocsize= {,no}attr2 barrier dmapi
{,no}grpid {bsd,sysv}groups ihashsize= {,no}ikeep
inode{32,64} {,no}largeio logbufs= logbsize= logdev=
rtdev= mtpt= noalign norecovery nouuid osyncisosync
{u,g,p}qnoenforce {,u,usr,g,grp,p,prj}quota sunit= swidth=
swalloc' -- "$cur"))
_comp_compgen -a -- -W 'allocsize= {,no}attr2 barrier dmapi
{,no}grpid {bsd,sysv}groups ihashsize= {,no}ikeep
inode{32,64} {,no}largeio logbufs= logbsize= logdev=
rtdev= mtpt= noalign norecovery nouuid osyncisosync
{u,g,p}qnoenforce {,u,usr,g,grp,p,prj}quota sunit=
swidth= swalloc'
;;&
esac
# COMP_WORDBREAKS is a real pain in the ass
Expand All @@ -213,10 +215,10 @@ _comp_cmd_mount()
esac

if [[ $cur == -* ]]; then
COMPREPLY=($(compgen -W '--version --help --verbose --all --fork
--fake --internal-only -l --no-mtab --no-canonicalize --pass-fd -s
_comp_compgen -- -W '--version --help --verbose --all --fork --fake
--internal-only -l --no-mtab --no-canonicalize --pass-fd -s
--read-only --rw -L -U --types --test-opts --options --bind --rbind
--move' -- "$cur"))
--move'
[[ ${COMPREPLY-} ]] && return
fi

Expand Down
35 changes: 14 additions & 21 deletions completions/_nmcli
Original file line number Diff line number Diff line change
Expand Up @@ -76,8 +76,8 @@ _comp_cmd_nmcli()

if ((cword == 1)); then
if [[ $cur == -* ]]; then
COMPREPLY=($(compgen -W '--terse --pretty --mode --fields
--escape --version --help' -- "$cur"))
_comp_compgen -- -W '--terse --pretty --mode --fields --escape
--version --help'
else
_comp_compgen -- -W "nm con dev"
fi
Expand Down Expand Up @@ -110,8 +110,8 @@ _comp_cmd_nmcli()
;;
esac

COMPREPLY=($(compgen -W 'status permissions enable sleep
wifi wwan wimax' -- "$cur"))
_comp_compgen -- -W 'status permissions enable sleep wifi wwan
wimax'
;;
con)
case $command in
Expand All @@ -121,11 +121,9 @@ _comp_cmd_nmcli()
;;
up)
if [[ $cur == -* ]]; then
COMPREPLY=($(compgen -W '--nowait --timeout' \
-- "$cur"))
_comp_compgen -- -W '--nowait --timeout'
else
COMPREPLY=($(compgen -W 'id uuid iface ap nsp' \
-- "$cur"))
_comp_compgen -- -W 'id uuid iface ap nsp'
fi
return
;;
Expand All @@ -139,8 +137,7 @@ _comp_cmd_nmcli()
;;
esac

COMPREPLY=($(compgen -W 'list status up down delete' \
-- "$cur"))
_comp_compgen -- -W 'list status up down delete'
;;
dev)
case $command in
Expand All @@ -150,8 +147,7 @@ _comp_cmd_nmcli()
;;
disconnect)
if [[ $cur == -* ]]; then
COMPREPLY=($(compgen -W '--nowait --timeout' \
-- "$cur"))
_comp_compgen -- -W '--nowait --timeout'
else
_comp_compgen -- -W 'iface'
fi
Expand All @@ -162,21 +158,19 @@ _comp_cmd_nmcli()

case $subcommand in
list)
COMPREPLY=($(compgen -W 'iface bssid' \
-- "$cur"))
_comp_compgen -- -W 'iface bssid'
return
;;
connect)
if [[ $cur == -* ]]; then
COMPREPLY=($(compgen -W '--private
--nowait --timeout' -- "$cur"))
_comp_compgen -- -W '--private --nowait
--timeout'
else
if [[ $prev == "connect" ]]; then
_comp_cmd_nmcli__ap_ssid
else
COMPREPLY=($(compgen -W 'password
wep-key-type iface bssid name' \
-- "$cur"))
_comp_compgen -- -W 'password
wep-key-type iface bssid name'
fi
fi
return
Expand All @@ -188,8 +182,7 @@ _comp_cmd_nmcli()
;;
esac

COMPREPLY=($(compgen -W 'status list disconnect wifi' \
-- "$cur"))
_comp_compgen -- -W 'status list disconnect wifi'
;;
esac

Expand Down
Loading