summary refs log tree commit diff
path: root/bin/beep
diff options
context:
space:
mode:
Diffstat (limited to 'bin/beep')
-rwxr-xr-xbin/beep75
1 files changed, 45 insertions, 30 deletions
diff --git a/bin/beep b/bin/beep
index 4dc53fb..cbdfc15 100755
--- a/bin/beep
+++ b/bin/beep
@@ -1,31 +1,34 @@
 #!/bin/sh
 
+set -e
+[ -n "$DEBUG" ] && set -x
+
 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
+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 ;;
-		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
-			;;
+	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))
@@ -33,9 +36,19 @@ shift $((OPTIND - 1))
 (
 	echo ${PPID}
 
-	[ -z "${nobel}" ] && tput bel &
+	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 "${nonotify}" ]; then
 		if [ -z "$*" ]; then
 			notify-send -a beep -u normal -i "${icon}" "${subject}" "${message}" &
 		else
@@ -43,14 +56,16 @@ shift $((OPTIND - 1))
 		fi
 	fi
 
-	if [ ! -f "${snd}" ]; then
-		case "${1}" in
+	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
+			esac
+		fi
+		paplay \
+			--property=media.role=event \
+			--volume="${vol}" \
+			"${snd}"
 	fi
-	paplay \
-		--property=media.role=event \
-		--volume="${vol}" \
-		"${snd}"
 ) &