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

vol=${BEEP_VOL:-0.5}
snd=${BEEP_SND:-$HOME/Music/sounds/miui/}
subject=${BEEP_SUB:-Beep}
message=${BEEP_MSG:-"<i>The bell rang</i>"}
icon=${BEEP_ICN:-"$(iconez -p $PPID | head -n1)"}
nobel=
nonotify=
while getopts v:s:S:M:i:bNh 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 ;;
		h | ?)
			printf "usage: %s [-h] -- NOTIFY_SEND_ARGS\n" "$(basename "$0")"
			printf "\n"
			printf "  -v \t volume (default: ${vol})\n"
			printf "  -s \t sound file (default: ${snd})\n"
			printf "  -b \t don't sound terminal bell (default: false)\n"
			printf "  -N \t don't send notification (default: false)\n"
			printf "\n"
			exit 2
			;;
	esac
done
shift $((OPTIND - 1))

(
	echo ${PPID}

	[ -z "${nobel}" ] && tput bel &

	if [ -z "${nonotify}" ]; then
		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 [ ! -f "${snd}" ]; then
		case "${1}" in
			done) snd=${snd}/complete.ogg ;;
			*) snd=${snd}/bell.ogg ;;
		esac
	fi
	paplay \
		--property=media.role=event \
		--volume="${vol}" \
		"${snd}"
) &