summaryrefslogtreecommitdiffstats
path: root/bash-completion/wdctl
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/wdctl
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/wdctl')
-rw-r--r--bash-completion/wdctl14
1 files changed, 10 insertions, 4 deletions
diff --git a/bash-completion/wdctl b/bash-completion/wdctl
index 4f16e7607..811b5e3cc 100644
--- a/bash-completion/wdctl
+++ b/bash-completion/wdctl
@@ -23,11 +23,17 @@ _wdctl_module()
return 0
;;
'-o'|'--output')
- # FIXME: how to append to a string with compgen?
- local OUTPUT
- OUTPUT="FLAG DESCRIPTION STATUS BOOT-STATUS DEVICE"
+ local prefix realcur OUTPUT_ALL OUTPUT
+ realcur="${cur##*,}"
+ prefix="${cur%$realcur}"
+ OUTPUT_ALL="FLAG DESCRIPTION STATUS BOOT-STATUS DEVICE"
+ 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
;;
'-s'|'--settimeout')