Add zsh anything.el plugin
[zsh.git] / .zsh / zaw / sources / process.zsh
1 # zaw source for processes
2
3 function zaw-src-process () {
4 local ps_list title ps pid_list
5 if [ $(uname) = "Darwin" ] ; then # for Macintosh
6 ps_list="$(ps aux | awk '$11 !~ /^\[/ {print $0}')" # filter out kernel processes
7 else
8 ps_list="$(ps -aux --sort args | awk '$11 !~ /^\[/ {print $0}')" # filter out kernel processes
9 fi
10 title="${${(f)ps_list}[1]}"
11 ps="$(echo $ps_list | sed '1d')"
12 pid_list="$(echo $ps | awk '{print $2}')"
13 : ${(A)candidates::=${(f)pid_list}}
14 : ${(A)cand_descriptions::=${(f)ps}}
15 actions=(zaw-callback-append-to-buffer zaw-src-process-kill)
16 act_descriptions=("insert" "kill")
17 options=(-t "$title")
18 }
19
20 function zaw-src-process-kill () {
21 local user="$(ps -ho user $1)"
22 if [[ -z $user ]]; then
23 echo "process with PID=$1 is not found"
24 return 1
25 fi
26 if [[ $user = $USER ]]; then
27 BUFFER="kill $1"
28 else
29 BUFFER="sudo kill $1"
30 fi
31 zle accept-line
32 }
33
34 zaw-register-src -n process zaw-src-process