From 86fbecb82fd72d2c16b8eb37db15666cb08ed7bd Mon Sep 17 00:00:00 2001 From: Cian Bagshaw Date: Fri, 16 Jun 2023 00:44:18 +0100 Subject: [PATCH] Expanded function of volume script Previously the volume was changed manually with 'amixer' and then 'gvol' ("get volume") was called to display the updated value, by again calling amixer. These two calls are unnecessary as the same output is given each time. Thus the whole process has been integrated into 'gvol', which can now set the volume as well as displaying it. --- .local/bin/gvol | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) diff --git a/.local/bin/gvol b/.local/bin/gvol index edbf5ba..26cd776 100755 --- a/.local/bin/gvol +++ b/.local/bin/gvol @@ -1,8 +1,11 @@ #!/bin/sh -# gvol - get volume of alsa control using amixer, with $1 as the control name, -# defaulting to Master if blank +# vol - get/set volume of alsa control using amixer +# $1: control name (default is 'Master') +# $2: set the volume to value (optional) -amixer get \ - $( [ -z "$1" ] && echo "Master" || echo "$1") \ - | sed -e '/\[on\]/ { s/\].*//; s/.*\[//; p; q }' \ - -e '/\[off\]/ { s/^.*$/MUTE/; p; q }' -n +amixer \ + $( [ -z "$2" ] && echo "get" || echo "set" ) \ + $( [ -z "$1" ] && echo "Master" || echo "$1" ) \ + "$2" \ + | sed -nE -e '/\[on\]/ { s/.*\[([0-9]+%)\].*/\1/; p; q }' \ + -e '/\[off\]/ { s/.*/MUTE/; p; q }' -- 2.20.1