sisyphus/scripts/notify.sh
Tibo De Peuter 94d31d31c4 Made the script more modular.
Made it so that options get 'parsed' and not always passed on. This
fixes progressbar values passed on to the notification manager when we
just want to display a title.
Made it so that the value of the progressbar doesn't have to be
calculated anymore.
Moved timeout responsibility for sysinfo category to dunstrc
2022-06-09 14:43:10 +02:00

68 lines
1.5 KiB
Bash
Executable file

#!/usr/bin/env bash
# Show system status in notification, or your own message
# Syntaxis: notify [-vb] [-t <timeout>] [<title> <message>]
# Requirements:
# - brightnessctl
panic () {
>&2 echo "Syntaxis: notify [-vb] [<title> [<message>]]"
exit 1
}
# Get options
while getopts ":bvt:" options; do
case "${options}" in
b)
value=$( brightnessctl | grep -o "[0-9]*%" | tr -d '%' )
title="Brightness: ${value}%"
category='sysinfo'
;;
v)
# Get volume (don't use pamixer because that is way slower)
value=$( pactl get-sink-volume @DEFAULT_SINK@ \
| cut -d '/' -f2 \
| grep -o '[0-9]*%' \
| tr -d '%' )
title="Volume: ${value}%"
category='sysinfo'
# If audio disabled, set value to zero.
if [ "$( pactl get-sink-mute @DEFAULT_SINK@ )" == "Mute: yes" ] ; then
title="Volume: ${value}% (Disabled)"
value=0
fi
;;
t)
timeout="${OPTARG}"
;;
*)
panic
;;
esac
done
shift $((OPTIND - 1))
# Check arguments
if [ $# -gt 2 ] ; then
panic
elif [ $# -gt 0 ] ; then
title="${1}"
message="${2:-}"
fi
# Build command string
arguments=""
if [[ ! -z "${category}" ]] ; then
arguments+=" -c ${category}"
fi
if [[ ! -z "${timeout}" ]] ; then
arguments+=" -t ${timeout}"
fi
if [[ ! -z "${value}" ]] ; then
arguments+=" -h int:value:${value}"
fi
notify-send "${title}" "${message}" ${arguments}