Improved gvol
authorCian Bagshaw <cian@cianb.xyz>
Sat, 11 Mar 2023 00:47:50 +0000 (00:47 +0000)
committerCian Bagshaw <cian@cianb.xyz>
Sat, 11 Mar 2023 00:47:50 +0000 (00:47 +0000)
Re-wrote most of the shell-script for getting volume info, to make it more
efficient.

.local/bin/gvol

index e26c1bc..29f43ba 100755 (executable)
@@ -1,19 +1,11 @@
 #!/bin/sh
 # gvol - get volume of alsa control using amixer, with $1 as the control name,
-# defaults to Master if blank
+# defaulting to Master if blank
 
-if [ $# == 1 ]
-then
-       CONTROL=$1 
-else
-       CONTROL=Master 
-fi
+[ -z "$1" ] && CONTROL=Master || CONTROL="$1"
 
-VOL=$(amixer get $CONTROL | grep Left:)
+VOL=$(amixer get $CONTROL | grep -m1 "%")
 
-if [ $(echo $VOL | awk '{print $6}') == "[off]" ]
-then
-       echo MUTE
-else
-       echo $(echo $VOL | awk '{print $5}' | tr -d [])
-fi
+[ $(grep -Fo "[on]" <<< "$VOL") ] \
+       && grep -o "[0-9]*%" <<< "$VOL" \
+       || echo MUTE