sisyphus/scripts/notify.sh

67 lines
1.4 KiB
Bash
Raw Normal View History

2022-04-28 13:43:42 +02:00
#!/usr/bin/env bash
# Show system status in notification, or your own message
2022-06-01 21:38:20 +02:00
# Syntaxis: notify [-vb] [<title> <message>]
2022-04-28 13:43:42 +02:00
2022-06-02 11:44:45 +02:00
# Requirements:
# - brightnessctl
# - pulsemixer
panic () {
>&2 echo "Syntaxis: notify [-vb] [<title> [<message>]]"
exit 1
}
2022-04-28 13:43:42 +02:00
# Get options
2022-06-01 21:38:20 +02:00
while getopts ":bv" options; do
2022-04-28 13:43:42 +02:00
case "${options}" in
b)
2022-06-02 11:44:45 +02:00
value=$( brightnessctl | grep -o "[0-9]*%" )
2022-04-28 13:43:42 +02:00
title="Brightness: ${value}"
2022-06-01 21:38:20 +02:00
timeout=2000
2022-06-03 11:20:17 +02:00
category='sysinfo'
2022-04-28 13:43:42 +02:00
;;
v)
2022-06-02 11:44:45 +02:00
# Get volume
value="$( pulsemixer --get-volume | cut -f1 -d' ' )%"
# If audio disabled
if [ ! "$( pulsemixer --get-mute )" -eq 0 ] ; then
width=0
value="${value} (Disabled)"
fi
2022-04-28 13:43:42 +02:00
title="Volume: ${value:-'0%'}"
2022-06-01 21:38:20 +02:00
timeout=2000
2022-06-03 11:20:17 +02:00
category='sysinfo'
2022-04-28 13:43:42 +02:00
;;
*)
2022-06-02 11:44:45 +02:00
panic
2022-04-28 13:43:42 +02:00
;;
esac
done
shift $((OPTIND - 1))
2022-06-01 21:38:20 +02:00
# Check arguments
2022-06-02 11:44:45 +02:00
if [ $# -gt 2 ] ; then
panic
elif [ $# -eq 2 ] ; then
2022-06-01 21:38:20 +02:00
title=$1
message=$2
2022-06-02 11:44:45 +02:00
elif [ $# -eq 1 ] ; then
2022-06-01 21:38:20 +02:00
title=$1
fi
# Calculate length of coloured bar.
2022-06-02 11:44:45 +02:00
if [[ "${value}" =~ ^[0-9]+%$ && "${width:--1}" -ne 0 ]] ; then
2022-06-01 21:38:20 +02:00
width=$(grep -o "[0-9]*" <<< "${value}")
fi
# Send message
notify-send "${title}" "${message}" \
-t "${timeout:=5000}" \
2022-06-03 11:20:17 +02:00
-c "${category:=''}" \
2022-06-01 21:38:20 +02:00
-h int:value:"${width:=0}" \
2022-06-02 11:44:45 +02:00
-h string:x-canonical-private-synchronous:byMe # Replace if previous still exists
2022-04-28 13:43:42 +02:00