From 4a323b1c212e8c1959de532b42fc786497136549 Mon Sep 17 00:00:00 2001 From: Tibo De Peuter Date: Thu, 2 Jun 2022 11:44:45 +0200 Subject: [PATCH] Fixed volume and message --- scripts/notify.sh | 44 +++++++++++++++++++++++++++++--------------- 1 file changed, 29 insertions(+), 15 deletions(-) diff --git a/scripts/notify.sh b/scripts/notify.sh index e74377d..f396bc4 100755 --- a/scripts/notify.sh +++ b/scripts/notify.sh @@ -2,25 +2,40 @@ # Show system status in notification, or your own message # Syntaxis: notify [-vb] [ <message>] +# Requirements: +# - brightnessctl +# - pulsemixer + +panic () { + >&2 echo "Syntaxis: notify [-vb] [<title> [<message>]]" + exit 1 +} + # Get options while getopts ":bv" options; do case "${options}" in b) - value=$(brightnessctl | grep -o "[0-9]*%") + value=$( brightnessctl | grep -o "[0-9]*%" ) title="Brightness: ${value}" timeout=2000 + class='top-center' ;; v) - value=$(pactl get-sink-volume @DEFAULT_SINK@ | cut -d '/' -f2 | grep -o '[0-9]*%') - status=$(amixer get Master | grep "^ Front Left" | cut -d ' ' -f 8) - if [[ $status != "[on]" ]] ; then - value="Disabled" - fi + # 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 + title="Volume: ${value:-'0%'}" timeout=2000 + class='top-center' ;; *) - title="Unknown option" + panic ;; esac done @@ -28,25 +43,24 @@ done shift $((OPTIND - 1)) # Check arguments -if [[ $# -gt 2 ]] ; then - >&2 echo "Syntaxis: notify [-vb] [<title> [<message>]]" - exit 1 -elif [[ $# -eq 2 ]] ; then +if [ $# -gt 2 ] ; then + panic +elif [ $# -eq 2 ] ; then title=$1 message=$2 -elif [[ $# -eq 1 ]] ; then +elif [ $# -eq 1 ] ; then title=$1 fi # Calculate length of coloured bar. -if [[ "${value}" =~ ^[0-9]+%$ ]] ; then +if [[ "${value}" =~ ^[0-9]+%$ && "${width:--1}" -ne 0 ]] ; then width=$(grep -o "[0-9]*" <<< "${value}") fi # Send message notify-send "${title}" "${message}" \ -t "${timeout:=5000}" \ - -c byMe \ + -c "${class:=''}" \ -h int:value:"${width:=0}" \ - -h string:x-canonical-private-synchronous:byMe # Replace if not yet gone + -h string:x-canonical-private-synchronous:byMe # Replace if previous still exists