summaryrefslogtreecommitdiff
path: root/scripts/nsend
blob: 81a852f6320af2afc5067be2aa1560eea64a61b1 (plain)
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
#!/bin/sh

help() {
cat << EOF
${0}: Wrapper script to send notifications

options:
 -s [Msg]	Send Msg
 -h 		Print this message and exit
EOF
}

err() {
	for line in "${@}"; do
		echo "${line}" >&2
	done
	exit 1
}

run() {
	if ! ${1} > /dev/null 2>&1; then
		err "${2}"
	fi

	[ -n "${3}" ] && echo "${3}"
	exit 0
}

if ! command -v notify-send > /dev/null 2>&1; then
	err "${0}: dunst must be installed"
fi

case "${1}" in
"-s")
	[ ${#} != 2 ] && err "${0}: Invalid usage" "Try '${0} -h' for help."

	run "notify-send ${2}" \
	"${0}: Failed to send notification"
;;
"-h") help; exit 0 ;;

*) err "${0}: Invalid usage" "Try '${0} -h' for help." ;;

esac