File: kill

package info (click to toggle)
yash 2.43-1
  • links: PTS, VCS
  • area: main
  • in suites: stretch
  • size: 7,184 kB
  • ctags: 3,159
  • sloc: ansic: 31,766; makefile: 812; sh: 407; sed: 16
file content (85 lines) | stat: -rw-r--r-- 1,504 bytes parent folder | download | duplicates (6)
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
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
# (C) 2010 magicant

# Completion script for the "kill" built-in command.

function completion/kill {

	typeset OPTIONS ARGOPT PREFIX
	OPTIONS=( #>#
	"s: n:; specify a signal to send"
	"l; print signal names"
	"v; print signal names and description"
	"--help"
	) #<#

	typeset signame=false SAVEWORDS
	SAVEWORDS=("$WORDS")
	command -f completion//parseoptions
	case $ARGOPT in
	(-)
		case $TARGETWORD in
		(-[[:upper:]]*)
			signame=true PREFIX=-
			;;
		(-[[:digit:]]*)
			typeset signame=true word
			for word in "${WORDS[2,-1]}" "${SAVEWORDS[2,-1]}"; do
				case $word in (-[ns[:upper:][:digit:]]*)
					signame=false
				esac
			done
			if $signame; then
				PREFIX=-
			fi
			;;
		(*)
			command -f completion//completeoptions
			return
			;;
		esac
		;;
	([ns])
		signame=true
		;;
	(*)
		typeset word
		for word in "${WORDS[2,-1]}"; do
			case $word in (-[lv])
				signame=true
			esac
		done
		;;
	esac

	if $signame; then
		complete -P "$PREFIX" --signal
	else
		typeset pid args
		case $TARGETWORD in
		(%*)
			# complete a job name
			complete -P % -j
			;;
		(-*)
			# complete a process group ID
			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=)
			;;
		(*)
			# complete a process ID
			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=)
			;;
		esac
	fi

}


# vim: set ft=sh ts=8 sts=8 sw=8 noet: