2022-04-28 13:43:42 +02:00
|
|
|
#!/usr/bin/env bash
|
|
|
|
# Show system status in notification, or your own message
|
2022-06-05 20:20:05 +02:00
|
|
|
# Syntaxis: notify [-vb] [-t <timeout>] [<title> <message>]
|
2022-04-28 13:43:42 +02:00
|
|
|
|
2022-06-02 11:44:45 +02:00
|
|
|
# Requirements:
|
|
|
|
# - brightnessctl
|
|
|
|
|
|
|
|
panic () {
|
|
|
|
>&2 echo "Syntaxis: notify [-vb] [<title> [<message>]]"
|
|
|
|
exit 1
|
|
|
|
}
|
|
|
|
|
2022-04-28 13:43:42 +02:00
|
|
|
# Get options
|
2022-06-05 20:20:05 +02:00
|
|
|
while getopts ":bvt:" options; do
|
2022-04-28 13:43:42 +02:00
|
|
|
case "${options}" in
|
|
|
|
b)
|
2022-06-09 14:43:10 +02:00
|
|
|
value=$( brightnessctl | grep -o "[0-9]*%" | tr -d '%' )
|
|
|
|
title="Brightness: ${value}%"
|
2022-06-03 11:20:17 +02:00
|
|
|
category='sysinfo'
|
2022-04-28 13:43:42 +02:00
|
|
|
;;
|
|
|
|
v)
|
2022-06-08 16:35:50 +02:00
|
|
|
# Get volume (don't use pamixer because that is way slower)
|
2022-06-09 14:43:10 +02:00
|
|
|
value=$( pactl get-sink-volume @DEFAULT_SINK@ \
|
|
|
|
| cut -d '/' -f2 \
|
|
|
|
| grep -o '[0-9]*%' \
|
|
|
|
| tr -d '%' )
|
|
|
|
title="Volume: ${value}%"
|
|
|
|
category='sysinfo'
|
2022-06-02 11:44:45 +02:00
|
|
|
|
2022-06-09 14:43:10 +02:00
|
|
|
# If audio disabled, set value to zero.
|
|
|
|
if [ "$( pactl get-sink-mute @DEFAULT_SINK@ )" == "Mute: yes" ] ; then
|
|
|
|
title="Volume: ${value}% (Disabled)"
|
|
|
|
value=0
|
2022-06-02 11:44:45 +02:00
|
|
|
fi
|
2022-04-28 13:43:42 +02:00
|
|
|
;;
|
2022-06-05 20:20:05 +02:00
|
|
|
t)
|
|
|
|
timeout="${OPTARG}"
|
|
|
|
;;
|
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
|
2022-06-09 14:43:10 +02:00
|
|
|
elif [ $# -gt 0 ] ; then
|
|
|
|
title="${1}"
|
|
|
|
message="${2:-}"
|
2022-06-01 21:38:20 +02:00
|
|
|
fi
|
|
|
|
|
2022-06-09 14:43:10 +02:00
|
|
|
# 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}"
|
2022-06-01 21:38:20 +02:00
|
|
|
fi
|
|
|
|
|
2022-06-09 14:43:10 +02:00
|
|
|
notify-send "${title}" "${message}" ${arguments}
|
2022-04-28 13:43:42 +02:00
|
|
|
|