_n-kill 814 Bytes
Newer Older
Sebastian Gniazdowski's avatar
Sebastian Gniazdowski committed
1
2
3
4
5
6
7
8
9
10
11
12
#compdef n-kill

local context ret=1

typeset -a list linewords
typeset -aU words wordbits
local line word
integer cygwin=0

local IFS="
"

13
14
case "$OSTYPE" in
    cygwin*) list=( `command ps -Wa` ); cygwin=1 ;;
Sebastian Gniazdowski's avatar
Sebastian Gniazdowski committed
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
    *) list=( `command ps -o pid,uid,command -A` ) ;;
esac

shift list

IFS=" "
for line in "${list[@]}"; do
    linewords=( $=line )
    if [ "$cygwin" = "1" ]; then
        linewords=( "${(@)linewords[8,-1]}" )
    else
        linewords=( "${(@)linewords[3,-1]}" )
    fi
    for word in "${linewords[@]}"; do
        if [ "$cygwin" = "1" ]; then
            wordbits=( "${(@s:\:)word}" )
        else
            wordbits=( "${(@s:/:)word}" )
        fi
        words+=( "${wordbits[@]}" )
    done
done

_wanted bits expl "Processes' name bits" \
    compadd "$@" -a - words && ret=0

return "$ret"