| 1 |
_taskset_module() |
| 2 |
{ |
| 3 |
local cur prev OPTS |
| 4 |
COMPREPLY=() |
| 5 |
cur="${COMP_WORDS[COMP_CWORD]}" |
| 6 |
prev="${COMP_WORDS[COMP_CWORD-1]}" |
| 7 |
case $prev in |
| 8 |
'-c'|'--cpu-list') |
| 9 |
local prefix realcur CPULIST_ALL CPULIST |
| 10 |
realcur="${cur##*,}" |
| 11 |
prefix="${cur%$realcur}" |
| 12 |
CPULIST_ALL=$(command sed 's/^/{/; s/-/../g; s/,/} {/g; s/$/}/' /sys/devices/system/cpu/online) |
| 13 |
for WORD in $(eval echo $CPULIST_ALL); do |
| 14 |
if ! [[ $prefix == *"$WORD"* ]]; then |
| 15 |
CPULIST="$WORD ${CPULIST:-""}" |
| 16 |
fi |
| 17 |
done |
| 18 |
compopt -o nospace |
| 19 |
COMPREPLY=( $(compgen -P "$prefix" -W "$CPULIST" -S ',' -- $realcur) ) |
| 20 |
return 0 |
| 21 |
;; |
| 22 |
'-p'|'--pid') |
| 23 |
local PIDS |
| 24 |
# FIXME: the pid argument is ambiguous. When |
| 25 |
# setting an affinity the optarg has to be cpu |
| 26 |
# mask. The following is good only for getting |
| 27 |
# affinity. |
| 28 |
PIDS=$(builtin cd /proc && echo [0-9]*) |
| 29 |
COMPREPLY=( $(compgen -W "$PIDS" -- $cur) ) |
| 30 |
return 0 |
| 31 |
;; |
| 32 |
'-h'|'--help'|'-V'|'--version') |
| 33 |
return 0 |
| 34 |
;; |
| 35 |
esac |
| 36 |
case $cur in |
| 37 |
-*) |
| 38 |
OPTS="--all-tasks --pid --cpu-list --help --version" |
| 39 |
COMPREPLY=( $(compgen -W "${OPTS[*]}" -- $cur) ) |
| 40 |
return 0 |
| 41 |
;; |
| 42 |
esac |
| 43 |
compopt -o bashdefault |
| 44 |
COMPREPLY=( $(compgen -c -- $cur) ) |
| 45 |
return 0 |
| 46 |
} |
| 47 |
complete -F _taskset_module taskset |