2013-03-24 12:10:55 -05:00
|
|
|
_taskset_module()
|
|
|
|
{
|
|
|
|
local cur prev OPTS
|
|
|
|
COMPREPLY=()
|
|
|
|
cur="${COMP_WORDS[COMP_CWORD]}"
|
|
|
|
prev="${COMP_WORDS[COMP_CWORD-1]}"
|
|
|
|
case $prev in
|
|
|
|
'-c'|'--cpu-list')
|
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>
2015-06-02 12:59:01 -05:00
|
|
|
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
|
2018-04-05 14:56:53 -05:00
|
|
|
CPULIST="$WORD ${CPULIST:-""}"
|
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>
2015-06-02 12:59:01 -05:00
|
|
|
fi
|
|
|
|
done
|
|
|
|
compopt -o nospace
|
|
|
|
COMPREPLY=( $(compgen -P "$prefix" -W "$CPULIST" -S ',' -- $realcur) )
|
2013-03-24 12:10:55 -05:00
|
|
|
return 0
|
|
|
|
;;
|
|
|
|
'-p'|'--pid')
|
|
|
|
local PIDS
|
|
|
|
# FIXME: the pid argument is ambiguous. When
|
|
|
|
# setting an affinity the optarg has to be cpu
|
|
|
|
# mask. The following is good only for getting
|
|
|
|
# affinity.
|
2017-08-26 07:45:13 -05:00
|
|
|
PIDS=$(cd /proc && echo [0-9]*)
|
2013-03-24 12:10:55 -05:00
|
|
|
COMPREPLY=( $(compgen -W "$PIDS" -- $cur) )
|
|
|
|
return 0
|
|
|
|
;;
|
2013-04-07 03:12:04 -05:00
|
|
|
'-h'|'--help'|'-V'|'--version')
|
|
|
|
return 0
|
|
|
|
;;
|
2013-03-24 12:10:55 -05:00
|
|
|
esac
|
|
|
|
case $cur in
|
|
|
|
-*)
|
2013-04-07 03:12:08 -05:00
|
|
|
OPTS="--all-tasks --pid --cpu-list --help --version"
|
2013-03-24 12:10:55 -05:00
|
|
|
COMPREPLY=( $(compgen -W "${OPTS[*]}" -- $cur) )
|
|
|
|
return 0
|
|
|
|
;;
|
|
|
|
esac
|
|
|
|
compopt -o bashdefault
|
|
|
|
COMPREPLY=( $(compgen -c -- $cur) )
|
|
|
|
return 0
|
|
|
|
}
|
|
|
|
complete -F _taskset_module taskset
|