summaryrefslogtreecommitdiffstats
path: root/bash-completion/swapon
diff options
context:
space:
mode:
authorBoris Egorov2015-06-02 19:59:01 +0200
committerKarel Zak2015-06-08 12:09:48 +0200
commitb5b80e5a6d85a53c89e8ef1ddb76ae985a1c7f65 (patch)
treefacd8becf5d26541bc24d67e51fa52652ef09df4 /bash-completion/swapon
parentlibsmartcols: keep JSON field names lower-case (diff)
downloadkernel-qcow2-util-linux-b5b80e5a6d85a53c89e8ef1ddb76ae985a1c7f65.tar.gz
kernel-qcow2-util-linux-b5b80e5a6d85a53c89e8ef1ddb76ae985a1c7f65.tar.xz
kernel-qcow2-util-linux-b5b80e5a6d85a53c89e8ef1ddb76ae985a1c7f65.zip
bash-completion: handle comma-separated options
This solution can become messy when you have too many options listed, because it repeats all of them. For example, after invoking completion with this input: $ partx --output END,SECTORS,SCHEME,START, You got these completions: END,SECTORS,SCHEME,START,FLAGS, END,SECTORS,SCHEME,START,NR, END,SECTORS,SCHEME,START,TYPE, END,SECTORS,SCHEME,START,NAME, END,SECTORS,SCHEME,START,SIZE, END,SECTORS,SCHEME,START,UUID, Nevertheless, it works even with numbers (listed options properly excluded from completion). Try to invoke completion after 'chcpu --disable ' or 'lsblk --exclude ' to see it in action. Few issues remained: * completion interrupts after encountering ':' in listed option, like in 'MAJ:MIN' in lsblk, losetup. * lscpu completion is broken: it inserts space after '--extended', but lscpu assumes there is no space after this option. It also doesn't complete '--parse' option. * some completion options are outdated (for example, lscpu MMHZ). We need to sync them with code. Fix for lscpu follows. Signed-off-by: Boris Egorov <egorov@linux.com>
Diffstat (limited to 'bash-completion/swapon')
-rw-r--r--bash-completion/swapon14
1 files changed, 10 insertions, 4 deletions
diff --git a/bash-completion/swapon b/bash-completion/swapon
index f471e079c..fc80af5eb 100644
--- a/bash-completion/swapon
+++ b/bash-completion/swapon
@@ -12,11 +12,17 @@ _swapon_module()
return 0
;;
'--show')
- # FIXME: how to append to a string with compgen?
- local OUTPUT
- OUTPUT="NAME TYPE SIZE USED PRIO UUID LABEL"
+ local prefix realcur OUTPUT_ALL OUTPUT
+ realcur="${cur##*,}"
+ prefix="${cur%$realcur}"
+ OUTPUT_ALL="NAME TYPE SIZE USED PRIO UUID LABEL"
+ for WORD in $OUTPUT_ALL; do
+ if ! [[ $prefix == *"$WORD"* ]]; then
+ OUTPUT="$WORD $OUTPUT"
+ fi
+ done
compopt -o nospace
- COMPREPLY=( $(compgen -W "$OUTPUT" -S ',' -- $cur) )
+ COMPREPLY=( $(compgen -P "$prefix" -W "$OUTPUT" -S ',' -- $realcur) )
return 0
;;
'-U')