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
This commit is contained in:
parent
13556a82d6
commit
94d31d31c4
1 changed files with 27 additions and 29 deletions
|
@ -4,7 +4,6 @@
|
||||||
|
|
||||||
# Requirements:
|
# Requirements:
|
||||||
# - brightnessctl
|
# - brightnessctl
|
||||||
# - pulsemixer
|
|
||||||
|
|
||||||
panic () {
|
panic () {
|
||||||
>&2 echo "Syntaxis: notify [-vb] [<title> [<message>]]"
|
>&2 echo "Syntaxis: notify [-vb] [<title> [<message>]]"
|
||||||
|
@ -15,24 +14,24 @@ panic () {
|
||||||
while getopts ":bvt:" options; do
|
while getopts ":bvt:" options; do
|
||||||
case "${options}" in
|
case "${options}" in
|
||||||
b)
|
b)
|
||||||
value=$( brightnessctl | grep -o "[0-9]*%" )
|
value=$( brightnessctl | grep -o "[0-9]*%" | tr -d '%' )
|
||||||
title="Brightness: ${value}"
|
title="Brightness: ${value}%"
|
||||||
timeout=2000
|
|
||||||
category='sysinfo'
|
category='sysinfo'
|
||||||
;;
|
;;
|
||||||
v)
|
v)
|
||||||
# Get volume (don't use pamixer because that is way slower)
|
# 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]*%')
|
value=$( pactl get-sink-volume @DEFAULT_SINK@ \
|
||||||
|
| cut -d '/' -f2 \
|
||||||
# If audio disabled
|
| grep -o '[0-9]*%' \
|
||||||
if [ ! "$( pactl get-sink-mute @DEFAULT_SINK@ )" -eq "Mute: yes" ] ; then
|
| tr -d '%' )
|
||||||
width=0
|
title="Volume: ${value}%"
|
||||||
value="${value} (Disabled)"
|
|
||||||
fi
|
|
||||||
|
|
||||||
title="Volume: ${value:-'0%'}"
|
|
||||||
timeout=2000
|
|
||||||
category='sysinfo'
|
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)
|
t)
|
||||||
timeout="${OPTARG}"
|
timeout="${OPTARG}"
|
||||||
|
@ -48,23 +47,22 @@ shift $((OPTIND - 1))
|
||||||
# Check arguments
|
# Check arguments
|
||||||
if [ $# -gt 2 ] ; then
|
if [ $# -gt 2 ] ; then
|
||||||
panic
|
panic
|
||||||
elif [ $# -eq 2 ] ; then
|
elif [ $# -gt 0 ] ; then
|
||||||
title=$1
|
title="${1}"
|
||||||
message=$2
|
message="${2:-}"
|
||||||
elif [ $# -eq 1 ] ; then
|
|
||||||
title=$1
|
|
||||||
fi
|
fi
|
||||||
|
|
||||||
# Calculate length of coloured bar.
|
# Build command string
|
||||||
if [[ "${value}" =~ ^[0-9]+%$ && "${width:--1}" -ne 0 ]] ; then
|
arguments=""
|
||||||
width=$(grep -o "[0-9]*" <<< "${value}")
|
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
|
fi
|
||||||
|
|
||||||
# Send message
|
notify-send "${title}" "${message}" ${arguments}
|
||||||
notify-send "${title}" "${message}" \
|
|
||||||
-t "${timeout:=5000}" \
|
|
||||||
-c "${category:=''}" \
|
|
||||||
-h int:value:"${width:=0}" \
|
|
||||||
-h string:wired-tag:byMe \
|
|
||||||
-h string:x-canonical-private-synchronous:byMe # Replace if previous still exists
|
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue