From 5d3966cc19d525df67781cdc2007b5196e579c02 Mon Sep 17 00:00:00 2001 From: Riyyi Date: Tue, 10 Apr 2018 11:05:35 +0200 Subject: [PATCH] Make volume.sh more maintainable, remove head call --- .scripts/wm/volume.sh | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/.scripts/wm/volume.sh b/.scripts/wm/volume.sh index 9ab2b21..94e7387 100755 --- a/.scripts/wm/volume.sh +++ b/.scripts/wm/volume.sh @@ -13,10 +13,11 @@ case $BLOCK_BUTTON in 5) amixer -q -D $MIXER sset $INSTANCE ${STEP}- unmute ;; # scroll down, decrease esac -INFO=$(amixer -D $MIXER get $INSTANCE) +INFO="amixer -D $MIXER get $INSTANCE" volume() { - VOLUME=$(echo $INFO | sed -nr 's/.*\[([0-9]*)%\].*/\1/p' | head -n 1) + VOLUME="$(${INFO} | \ + awk '/\[[0-9]+%\]/ { print substr($5, 2, length($5) - 3); exit }')" } symbol() { @@ -31,13 +32,13 @@ symbol() { } setOutput() { - # If sound is not muted - if [ -n "$(echo $INFO | sed -nr 's/(\[on\])/\1/p')" ]; then + # If sound is not muted + if [ -n "$(${INFO} | sed -nr 's/(\[on\])/\1/p')" ]; then COLOR="#FFF" volume symbol VOLUME="$VOLUME%" - else + else COLOR="#676E7D" VOLUME="MUTE" SYMBOL=""