summaryrefslogtreecommitdiffstats
path: root/bash-completion/taskset
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/taskset
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/taskset')
-rw-r--r--bash-completion/taskset16
1 files changed, 11 insertions, 5 deletions
diff --git a/bash-completion/taskset b/bash-completion/taskset
index dd1ef1f69..8e62a3b67 100644
--- a/bash-completion/taskset
+++ b/bash-completion/taskset
@@ -6,11 +6,17 @@ _taskset_module()
prev="${COMP_WORDS[COMP_CWORD-1]}"
case $prev in
'-c'|'--cpu-list')
- 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
;;
'-p'|'--pid')