1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60
|
# (C) 2010 magicant
# Completion script for the "renice" command.
# Supports POSIX 2008 and the traditional syntax.
function completion/renice {
typeset OPTIONS ARGOPT PREFIX
OPTIONS=( #>#
"g; treat operands as process group IDs"
"n:; specify the nice value increment"
"p; treat operands as process IDs"
"u; treat operands as user names"
) #<#
command -f completion//parseoptions -e
case $ARGOPT in
(-)
command -f completion//completeoptions
;;
('')
typeset type=pid arg
for arg in "${WORDS[2,-1]}"; do
case $arg in
(-p|--pid) type=pid ;;
(-g|--pgrp) type=pgrp ;;
(-u|--user) type=user ;;
esac
done
case $type in
(pid)
# complete a process ID
typeset pid args
while read -r pid args; do
if kill -n 0 $pid; then
complete -D "$args" -- "$pid"
fi
done 2>/dev/null <(ps -A -o pid= -o args=)
;;
(pgrp)
# complete a process group ID
typeset pid args
while read -r pid args; do
if kill -n 0 -$pid; then
complete -D "$args" -- "$pid"
fi
done 2>/dev/null <(ps -A -o pgid= -o args=)
;;
(user)
# complete a user name
complete -u
;;
esac
;;
esac
}
# vim: set ft=sh ts=8 sts=8 sw=8 et:
|