summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorzachir <zachir@librem.one>2023-02-21 02:20:48 -0600
committerzachir <zachir@librem.one>2023-02-21 02:20:48 -0600
commit34143572a5ab8ba3a2aa2bf89082633df439bff6 (patch)
treed2f806ad0c5d41eca721285dc70109f43a2aa255
parent21c74748679f7badc8f068ccb000685839912b8e (diff)
Add ability to specify volume inc/dec amount
-rwxr-xr-xvolsv42
-rw-r--r--volsv.114
2 files changed, 40 insertions, 16 deletions
diff --git a/volsv b/volsv
index a34d591..6c59379 100755
--- a/volsv
+++ b/volsv
@@ -1,5 +1,7 @@
#!/bin/sh
+re='^[0-9]+$'
+
#{{{ detect
detect () {
if pgrep -x pulseaudio >/dev/null; then
@@ -16,17 +18,17 @@ detect () {
#{{{ up
up () {
- [ -n "$SNDIO" ] && sndioctl output.level=+0.05
- [ -n "$PULSE$PIPEWIRE" ] && pamixer -i 5
- [ -n "$ALSA" ] && amixer sset Master 5%+
+ [ -n "$SNDIO" ] && sndioctl output.level=+"$(printf "%0.02f" "$(( amt * 0.01 ))")"
+ [ -n "$PULSE$PIPEWIRE" ] && pamixer -i $amt
+ [ -n "$ALSA" ] && amixer sset Master "${amt}%+"
}
#}}}
#{{{ down
down () {
- [ -n "$SNDIO" ] && sndioctl output.level=-0.05
- [ -n "$PULSE$PIPEWIRE" ] && pamixer -d 5
- [ -n "$ALSA" ] && amixer sset Master 5%-
+ [ -n "$SNDIO" ] && sndioctl output.level=-"$(printf "%0.02f" "$(( amt * 0.01 ))")"
+ [ -n "$PULSE$PIPEWIRE" ] && pamixer -d $amt
+ [ -n "$ALSA" ] && amixer sset Master "${amt}%-"
}
#}}}
@@ -87,8 +89,8 @@ volsv: volume setter v, sets the volume despite the sound server
supported sound servers are sndio, pulseaudio, pipewire, and alsa (no bluealsa)
Actions:
- -i Increase the volume
- -d Decrease the volume
+ -i x Increase the volume by x (5% if not given)
+ -d x Decrease the volume by x (5% if not given)
-t Mute the default output
-m Mute the default mic
-v Get the volume of the default output
@@ -100,8 +102,28 @@ EOF
#{{{ getopts
while getopts "idtmvga" o; do case "${o}" in
- i) setact up || exit 1 ;;
- d) setact down || exit 1 ;;
+ i)
+ eval nextopt=\${$OPTIND}
+ if [ -n "$nextopt" -a "$nextopt" != "-*" ]; then
+ OPTIND=$((OPTIND + 1))
+ amt=$nextopt
+ fi
+ case "$amt" in
+ ''|*[!0-9]*) amt=5 ;;
+ esac
+ setact up || exit 1
+ ;;
+ d)
+ eval nextopt=\${$OPTIND}
+ if [ -n "$nextopt" -a "$nextopt" != "-*" ]; then
+ OPTIND=$((OPTIND + 1))
+ amt=$nextopt
+ fi
+ case "$amt" in
+ ''|*[!0-9]*) amt=5 ;;
+ esac
+ setact down || exit 1
+ ;;
t) setact mute || exit 1 ;;
m) setact micm || exit 1 ;;
v) setact getv || exit 1 ;;
diff --git a/volsv.1 b/volsv.1
index e57aa52..d70dd7c 100644
--- a/volsv.1
+++ b/volsv.1
@@ -3,8 +3,10 @@
volsv \- volume set variable
.SH SYNOPSIS
.B volsv
-.RB [ \-i ]
-.RB [ \-d ]
+.RB [ \-i
+.IR x ]
+.RB [ \-d
+.IR x ]
.RB [ \-t ]
.RB [ \-m ]
.RB [ \-v ]
@@ -24,11 +26,11 @@ for pipewire, and/or mixerd for sndio.
.B \-h
volsv displays help message
.TP
-.B \-i
-volsv increases the volume by 5%
+.BI \-i " x"
+volsv increases the volume by x% (or 5 if x is not provided, or not an integer)
.TP
-.B \-d
-volsv decreases the volume by 5%
+.BI \-d " x"
+volsv decreases the volume by x% (or 5 if x is not provided, or not an integer)
.TP
.B \-t
volsv will toggle the volume mute