diff options
author | Boris Egorov | 2015-06-02 19:59:01 +0200 |
---|---|---|
committer | Karel Zak | 2015-06-08 12:09:48 +0200 |
commit | b5b80e5a6d85a53c89e8ef1ddb76ae985a1c7f65 (patch) | |
tree | facd8becf5d26541bc24d67e51fa52652ef09df4 /bash-completion/chcpu | |
parent | libsmartcols: keep JSON field names lower-case (diff) | |
download | kernel-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/chcpu')
-rw-r--r-- | bash-completion/chcpu | 32 |
1 files changed, 22 insertions, 10 deletions
diff --git a/bash-completion/chcpu b/bash-completion/chcpu index da9c6caf0..33991f4a8 100644 --- a/bash-completion/chcpu +++ b/bash-completion/chcpu @@ -6,19 +6,31 @@ _chcpu_module() prev="${COMP_WORDS[COMP_CWORD-1]}" case $prev in '-e'|'--enable') - local CPULIST - # FIXME: will propose only binding to a cpu. - # Maybe this should add comma, and continue? - CPULIST=$(sed 's/^/{/; s/-/../g; s/,/} {/g; s/$/}/' /sys/devices/system/cpu/offline) - COMPREPLY=( $(compgen -W "$(eval echo $CPULIST)" -- $cur) ) + local prefix realcur CPULIST_ALL CPULIST + realcur="${cur##*,}" + prefix="${cur%$realcur}" + CPULIST_ALL=$(sed 's/^/{/; s/-/../g; s/,/} {/g; s/$/}/' /sys/devices/system/cpu/offline) + for WORD in $(eval echo $CPULIST_ALL); do + if ! [[ $prefix == *"$WORD"* ]]; then + CPULIST="$WORD $CPULIST" + fi + done + compopt -o nospace + COMPREPLY=( $(compgen -P "$prefix" -W "$CPULIST" -S ',' -- $realcur) ) return 0 ;; '-d'|'--disable') - local CPULIST - # FIXME: will propose only binding to a cpu. - # Maybe this should add comma, and continue? - CPULIST=$(sed 's/^/{/; s/-/../g; s/,/} {/g; s/$/}/' /sys/devices/system/cpu/online) - COMPREPLY=( $(compgen -W "$(eval echo $CPULIST)" -- $cur) ) + local prefix realcur CPULIST_ALL CPULIST + realcur="${cur##*,}" + prefix="${cur%$realcur}" + CPULIST_ALL=$(sed 's/^/{/; s/-/../g; s/,/} {/g; s/$/}/' /sys/devices/system/cpu/online) + for WORD in $(eval echo $CPULIST_ALL); do + if ! [[ $prefix == *"$WORD"* ]]; then + CPULIST="$WORD $CPULIST" + fi + done + compopt -o nospace + COMPREPLY=( $(compgen -P "$prefix" -W "$CPULIST" -S ',' -- $realcur) ) return 0 ;; '-c'|'--configure'|'-g'|'--deconfigure') |