1 # Copy this file into /usr/share/zsh/site-functions/
2 # and add 'autoload n-kill` to .zshrc
4 # This function allows to choose a process and a signal to send to it
16 [ -f ~/.config/znt/n-list.conf ] && builtin source ~/.config/znt/n-list.conf
17 [ -f ~/.config/znt/n-kill.conf ] && builtin source ~/.config/znt/n-kill.conf
38 NLIST_REMEMBER_STATE=0
40 typeset -a NLIST_NONSELECTABLE_ELEMENTS
41 NLIST_NONSELECTABLE_ELEMENTS=( 1 )
43 type ps 2>/dev/null 1>&2 || { echo >&2 "Error: \`ps' not found"; return 1 }
46 CYGWIN*) list=( `command ps -Wa` ) ;;
47 *) list=( `command ps -o pid,uid,command -A` ) ;;
51 title=$'\x1b[00;31m'"${list[1]}"$'\x1b[00;00m\0'
53 list=( "$title" "${(@M)list:#(#i)*$1*}" )
55 local NLIST_GREP_STRING="$1"
57 if [ "$#list" -eq 1 ]; then
58 echo "No matching processes"
64 # Got answer? (could be Ctrl-C or 'q')
65 if [ "$REPLY" -gt 0 ]; then
66 selected="$reply[REPLY]"
67 selected="${selected## #}"
71 signal_names=( ${(vin)signals} )
72 typeset -a NLIST_HOP_INDEXES
73 NLIST_HOP_INDEXES=( 3 6 8 )
74 unset NLIST_COLORING_PATTERN
75 n-list $'\x1b[00;31mSelect signal:\x1b[00;00m' "$signal_names[@]"
77 if [ "$REPLY" -gt 0 ]; then
78 selected="$reply[REPLY]"
79 signal="${(k)signals[(r)$selected]}"
82 if [ "${(t)CURSOR}" = "integer-local-special" ]; then
85 zle -U "kill -$signal $pid"
87 print -zr "kill -$signal $pid"
90 [ "${(t)CURSOR}" = "integer-local-special" ] && zle redisplay
93 [ "${(t)CURSOR}" = "integer-local-special" ] && zle redisplay
96 # vim: set filetype=zsh: