sisyphus/scripts/notify.sh

53 lines
1.2 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
# 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)
value=$(brightnessctl | grep -o "[0-9]*%")
title="Brightness: ${value}"
2022-06-01 21:38:20 +02:00
timeout=2000
2022-04-28 13:43:42 +02:00
;;
v)
value=$(pactl get-sink-volume @DEFAULT_SINK@ | cut -d '/' -f2 | grep -o '[0-9]*%')
2022-06-01 21:38:20 +02:00
status=$(amixer get Master | grep "^ Front Left" | cut -d ' ' -f 8)
if [[ $status != "[on]" ]] ; then
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-04-28 13:43:42 +02:00
;;
*)
title="Unknown option"
;;
esac
done
shift $((OPTIND - 1))
2022-06-01 21:38:20 +02:00
# Check arguments
if [[ $# -gt 2 ]] ; then
>&2 echo "Syntaxis: notify [-vb] [<title> [<message>]]"
exit 1
elif [[ $# -eq 2 ]] ; then
title=$1
message=$2
elif [[ $# -eq 1 ]] ; then
title=$1
fi
# Calculate length of coloured bar.
if [[ "${value}" =~ ^[0-9]+%$ ]] ; then
width=$(grep -o "[0-9]*" <<< "${value}")
fi
# Send message
notify-send "${title}" "${message}" \
-t "${timeout:=5000}" \
2022-04-29 13:47:52 +02:00
-c byMe \
2022-06-01 21:38:20 +02:00
-h int:value:"${width:=0}" \
2022-04-28 13:43:42 +02:00
-h string:x-canonical-private-synchronous:byMe # Replace if not yet gone