From: Cian Bagshaw Date: Sat, 11 Mar 2023 00:47:50 +0000 (+0000) Subject: Improved gvol X-Git-Url: https://tests.cianb.xyz/?a=commitdiff_plain;h=1dc3bf18cbcc94b357e70f95ec2810fc817069b3;p=dotFiles Improved gvol Re-wrote most of the shell-script for getting volume info, to make it more efficient. --- diff --git a/.local/bin/gvol b/.local/bin/gvol index e26c1bc..29f43ba 100755 --- a/.local/bin/gvol +++ b/.local/bin/gvol @@ -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