summary refs log tree commit diff
path: root/bin/beep
blob: cbdfc15046b19976f1c511c4c4fdf7681af16c69 (plain) (blame)
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
#!/bin/sh

set -e
[ -n "$DEBUG" ] && set -x

vol=${BEEP_VOL:-0.5}
snd=${BEEP_SND:-$HOME/Music/sounds/miui/}
nobel=
nonotify=
nosnd=
while getopts v:s:S:M:i:BNAh opt; do
	case "$opt" in
	v) vol=${OPTARG} ;;
	s) snd=${OPTARG} ;;
	# S) subject=${OPTARG} ;;
	# M) message=${OPTARG} ;;
	# i) icon=${OPTARG} ;;
	N) nonotify=1 ;;
	B) nobel=1 ;;
	A) nosnd=1 ;;
	h | ?)
		printf "usage: %s [-h] -- NOTIFY_SEND_ARGS\n" "$(basename "$0")"
		printf "\n"
		printf "  -v \t volume (default: %s)\n" "${vol}"
		printf "  -s \t sound file (default: %s)\n" "${snd}"
		printf "  -B \t don't sound terminal bell (default: %b)\n" "${nobel}"
		printf "  -N \t don't send notification (default: %b)\n" "${nonotify}"
		printf "  -A \t don't play sound (default: %b)\n" "${nosnd}"
		printf "\n"
		exit 2
		;;
	esac
done
shift $((OPTIND - 1))

(
	echo ${PPID}

	if [ -z "${nobel}" ]; then
		if command -v tput >/dev/null; then
			tput bel &
		else
			(printf '\a' | doas tee -a /dev/console) &
		fi
	fi

	if [ -z "${nonotify}" ] && command -v notify-send >/dev/null; then
		subject=${BEEP_SUB:-Beep}
		message=${BEEP_MSG:-"<i>The bell rang</i>"}
		icon=${BEEP_ICN:-"$(iconez -p $PPID | head -n1)"}

		if [ -z "$*" ]; then
			notify-send -a beep -u normal -i "${icon}" "${subject}" "${message}" &
		else
			notify-send -a beep -u normal -i "${icon}" "$@" &
		fi
	fi

	if [ -z "${nosnd}" ] && command -v paplay >/dev/null; then
		if [ -d "${snd}" ]; then
			case "${1}" in
			done) snd=${snd}/complete.ogg ;;
			*) snd=${snd}/bell.ogg ;;
			esac
		fi
		paplay \
			--property=media.role=event \
			--volume="${vol}" \
			"${snd}"
	fi
) &