summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--README.md16
-rwxr-xr-xvolsv210
2 files changed, 122 insertions, 104 deletions
diff --git a/README.md b/README.md
index 996cd3f..6d2333a 100644
--- a/README.md
+++ b/README.md
@@ -19,7 +19,7 @@ in pipewire, pulseaudio, sndio, and ALSA. Once I get FreeBSD up and running, I w
It depends on:
- pamixer (pulseaudio/pipewire)
-- amixer (alsa)
+- amixer (alsa/pipewire mic mute)
- mixerd (sndio)
- pgrep (with the -x command, standard in BSD and \*/Linux systems)
@@ -34,12 +34,12 @@ I learn to write scripts.
#### Flags/Commands
-- increase volume: `up` or `-i`
-- decrease volume: `down` or `-d`
-- toggle system mute: `toggle` or `-t`
-- toggle microphone mute: `mic` or `-m`
-- get volume level: `getv` or `-v`
-- get mute state: `getm` or `-g`
-- get volume and mute: `getvm` or `-vm`
+- increase volume: `-i`
+- decrease volume: `-d`
+- toggle system mute: `-t`
+- toggle microphone mute: `-m`
+- get volume level: `-v`
+- get mute state: `-g`
+- get volume and mute: `-a`
- help message: `-h`
diff --git a/volsv b/volsv
index 960481a..a34d591 100755
--- a/volsv
+++ b/volsv
@@ -1,109 +1,127 @@
#!/bin/sh
-# print error message
-printerror () {
- echo "$1 is not a recognized command or flag"
+
+#{{{ detect
+detect () {
+ if pgrep -x pulseaudio >/dev/null; then
+ PULSE='y' ; unset PIPEWIRE SNDIO ALSA
+ elif pgrep -x pipewire >/dev/null; then
+ PIPEWIRE='y' ; unset PULSE SNDIO ALSA
+ elif pgrep -x sndiod >/dev/null; then
+ SNDIO='y' ; unset PIPEWIRE PULSE ALSA
+ else
+ ALSA='y' ; unset PIPEWIRE PULSE SNDIO
+ fi
}
-# if sndio
-sndiosv () {
- case "$1" in
- "up" | "-i") sndioctl output.level=+0.05 ;;
- "down" | "-d") sndioctl output.level=-0.05 ;;
- "toggle" | "-t") sndioctl output.mute=! ;;
- "mic" | "-m") sndioctl input.mute=! ;;
- "getv" | "-v") printf "%s%%" `sndioctl output.level | rev | cut -d'.' -f1 | rev | cut -c 1,2` ;;
- "getm" | "-g") sndioctl output.mute | cut -d'=' -f2 | sed 's/1/[off]/;s/0/[on]/' ;;
- "getvm" | "-vg") printf "%s%s%%" `sndioctl output.mute | cut -d'=' -f2 | sed 's/1/[off]/;s/0/[on]/'` `sndioctl output.level | rev | cut -d'.' -f1 | rev | cut -c 1,2` ;;
- *) printerror "$1" ;;
- esac
+#}}}
+
+#{{{ up
+up () {
+ [ -n "$SNDIO" ] && sndioctl output.level=+0.05
+ [ -n "$PULSE$PIPEWIRE" ] && pamixer -i 5
+ [ -n "$ALSA" ] && amixer sset Master 5%+
}
-# if pulseaudio
-pulsesv () {
+#}}}
+
+#{{{ down
+down () {
+ [ -n "$SNDIO" ] && sndioctl output.level=-0.05
+ [ -n "$PULSE$PIPEWIRE" ] && pamixer -d 5
+ [ -n "$ALSA" ] && amixer sset Master 5%-
+}
+#}}}
+
+#{{{ mute
+mute () {
case "$1" in
- "up" | "-i") pamixer -i 5 ;;
- "down" | "-d") pamixer -d 5 ;;
- "toggle" | "-t") pamixer -t ;;
- "mic" | "-m") pamixer --source 1 -t ;;
- "getv" | "-v") printf "%s%%\n" "$(pamixer --get-volume)" ;;
- "getm" | "-g") pamixer --get-mute | sed 's/[Ff]alse/\[on\]/;s/[Tt]rue/\[off\]/' ;;
- "getvm" | "-vg") printf "%s%s%%\n" `pamixer --get-mute | sed 's/[Ff]alse/\[on\]/;s/[Tt]rue/\[off\]/'` "$(pamixer --get-volume)" ;;
- *) printerror "$1" ;;
+ spr)
+ [ -n "$SNDIO" ] && sndioctl output.mute=!
+ [ -n "$PULSE$PIPEWIRE" ] && pamixer -t
+ [ -n "$ALSA" ] && amixer sset Master toggle
+ ;;
+ mic)
+ [ -n "$SNDIO" ] && sndioctl input.mute=!
+ [ -n "$PULSE" ] && pamixer --source 1 -t
+ [ -n "$PIPEWIRE$ALSA" ] && amixer sset Capture toggle
+ ;;
esac
}
-# if pipewire
-pwiresv () {
+#}}}
+
+#{{{ get
+get () {
case "$1" in
- "up" | "-i") pamixer -i 5 ;;
- "down" | "-d") pamixer -d 5 ;;
- "toggle" | "-t") pamixer -t ;;
- "mic" | "-m") amixer sset Capture toggle ;;
- "getv" | "-v") printf "%s%%\n" "$(pamixer --get-volume)" ;;
- "getm" | "-g") pamixer --get-mute | sed 's/[Ff]alse/\[on\]/;s/[Tt]rue/\[off\]/' ;;
- "getvm" | "-vg") printf "%s%s%%\n" `pamixer --get-mute | sed 's/[Ff]alse/\[on\]/;s/[Tt]rue/\[off\]/'` "$(pamixer --get-volume)" ;;
- *) printerror "$1" ;;
+ volu)
+ [ -n "$SNDIO" ] && printf "%s%%" `sndioctl output.level | rev | cut -d'.' -f1 | rev | cut -c 1,2`
+ [ -n "$PULSE$PIPEWIRE" ] && printf "%s%%\n" "$(pamixer --get-volume)"
+ [ -n "$ALSA" ] && amixer sget Master | grep '\[[0-9]*\%\]' | sed "s/ /\n/g" | grep '%' | sed 's/\[//;s/\]//g'
+ ;;
+ mute)
+ [ -n "$SNDIO" ] && sndioctl output.mute | cut -d'=' -f2 | sed 's/1/[off]/;s/0/[on]/'
+ [ -n "$PULSE$PIPEWIRE" ] && pamixer --get-mute | sed 's/[Ff]alse/\[on\]/;s/[Tt]rue/\[off\]/'
+ [ -n "$ALSA" ] && amixer sget Master | grep '\[o[fn]' | cut -d' ' -f8 | head -1
+ ;;
+ both)
+ [ -n "$SNDIO" ] && printf "%s%s%%" `sndioctl output.mute | cut -d'=' -f2 | sed 's/1/[off]/;s/0/[on]/'` `sndioctl output.level | rev | cut -d'.' -f1 | rev | cut -c 1,2`
+ [ -n "$PULSE$PIPEWIRE" ] && printf "%s%s%%\n" `pamixer --get-mute | sed 's/[Ff]alse/\[on\]/;s/[Tt]rue/\[off\]/'` "$(pamixer --get-volume)"
+ [ -n "$ALSA" ] && printf "%s%s" `amixer sget Master | grep '\[o[fn]' | cut -d' ' -f8 | head -1` `amixer sget Master | grep '\[[0-9]*\%\]' | sed "s/ /\n/g" | grep '%' | sed 's/\[//;s/\]//g'`
+ ;;
esac
}
-# if alsa
-alsasv () {
- DEVICE=`pgrep -x bluealsa >/dev/null && echo -n "bluealsa"`
- if [ -z "$DEVICE" ]; then
- case "$1" in
- "up" | "-i") amixer sset Master 5%+ ;;
- "down" | "-d") amixer sset Master 5%- ;;
- "toggle" | "-t") amixer sset Master toggle ;;
- "mic" | "-m") amixer sset Capture toggle ;;
- "getv" | "-v") amixer sget Master | grep '\[[0-9]*\%\]' | sed "s/ /\n/g" | grep '%' | sed 's/\[//;s/\]//g' ;;
- "getm" | "-g") amixer sget Master | grep '\[o[fn]' | cut -d' ' -f8 | head -1 ;;
- "getvm" | "-vg") printf "%s%s" `amixer sget Master | grep '\[o[fn]' | cut -d' ' -f8 | head -1` `amixer sget Master | grep '\[[0-9]*\%\]' | sed "s/ /\n/g" | grep '%' | sed 's/\[//;s/\]//g'` ;;
- *) printerror "$1" ;;
- esac
- elif [ -z `amixer -D $DEVICE controls` ]; then
- case "$1" in
- "up" | "-i") amixer sset Master 5%+ ;;
- "down" | "-d") amixer sset Master 5%- ;;
- "toggle" | "-t") amixer sset Master toggle ;;
- "mic" | "-m") amixer sset Capture toggle ;;
- "getv" | "-v") amixer sget Master | grep '\[[0-9]*\%\]' | sed "s/ /\n/g" | grep '%' | sed 's/\[//;s/\]//g' ;;
- "getm" | "-g") amixer sget Master | grep '\[o[fn]' | cut -d' ' -f8 | head -1 ;;
- "getvm" | "-vg") printf "%s%s" `amixer sget Master | grep '\[o[fn]' | cut -d' ' -f8 | head -1` `amixer sget Master | grep '\[[0-9]*\%\]' | sed "s/ /\n/g" | grep '%' | sed 's/\[//;s/\]//g'` ;;
- *) printerror "$1" ;;
- esac
+#}}}
+
+#{{{ setact
+setact() {
+ if [ -n "${action+x}" ] && [ "$action" != "$1" ]; then
+ echo "Running $1 with $action..."
+ echo "Incompatible options given. Only one action may be specified per run."
+ return 1
else
- MIXER=`amixer -D $DEVICE | grep 'A2DP' | cut -d"'" -f2`
- case "$1" in
- "up" | "-i") amixer -D "$DEVICE" sset "$MIXER" 5%+ ;;
- "down" | "-d") amixer -D "$DEVICE" sset "$MIXER" 5%- ;;
- "toggle" | "-t") amixer -D "$DEVICE" sset "$MIXER" toggle ;;
- "getv" | "-v") amixer -D "$DEVICE" sget "$MIXER" | grep '\[[0-9]*\%\]' | sed "s/ /\n/g" | grep '%' | sed 's/\[//;s/\]//g' | head -1;;
- "getm" | "-g") amixer -D "$DEVICE" sget "$MIXER" | grep '\[o[fn]' | cut -d' ' -f9 | head -1 ;;
- "getvm" | "-vg") printf "%s%s" `amixer -D "$DEVICE" sget "$MIXER" | grep '\[o[fn]' | cut -d' ' -f9 | head -1` `amixer -D "$DEVICE" sget "$MIXER" | grep '\[[0-9]*\%\]' | sed "s/ /\n/g" | grep '%' | sed 's/\[//;s/\]//g' | head -1` ;;
- *) printerror "$1" ;;
- esac
+ action="$1"
fi
}
-#Search input for
-echo "$@" | grep -q ' *-h *' && echo \
-"Volsv is Free software. You can use it for any purpose, but I make no guerantee about its usability or fitness "\
-"for any particular purpose. You are also free to redistribute, modify, and distribute your modifications to "\
-"volsv. Volsv is distributed under the BSD 3-Clause license to ensure full license compatibility with GNU, "\
-"Linux, and BSD operating systems. A copy of this license is included in the repository.\n\n"\
-"Volsv is a script designed to control the volume of a *NIX machine. The commands/flags are as follows:
-increase volume: 'up' or '-i'
-decrease volume: 'down' or '-d'
-toggle volume mute: 'toggle' or '-t'
-toggle mic mute: 'mic' or '-m'
-get volume level: 'getv' or '-v'
-get mute state: 'getm' or '-g'" && exit
+#}}}
-for i in $@; do
- if pgrep -x pulseaudio >/dev/null; then
- pulsesv $i
- elif pgrep -x pipewire >/dev/null; then
- pwiresv $i
- elif pgrep -x sndiod >/dev/null; then
- sndiosv $i
- else
- alsasv $i
- fi
- pgrep -x dwmblocks >/dev/null && sigdwmb volume
- #pgrep -x dwmbar >/dev/null && dwmbar-signal volume
-done
+#{{{ printhelp
+printhelp () { cat << EOF
+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
+ -t Mute the default output
+ -m Mute the default mic
+ -v Get the volume of the default output
+ -g Get the mute status of the default output
+ -a Get the volume and mute status of the default output
+EOF
+}
+#}}}
+
+#{{{ getopts
+while getopts "idtmvga" o; do case "${o}" in
+ i) setact up || exit 1 ;;
+ d) setact down || exit 1 ;;
+ t) setact mute || exit 1 ;;
+ m) setact micm || exit 1 ;;
+ v) setact getv || exit 1 ;;
+ g) setact getm || exit 1 ;;
+ a) setact geta || exit 1 ;;
+ *) printhelp ; exit 1 ;;
+esac done
+#}}}
+
+detect
+
+#{{{ action
+case "$action" in
+ up) up ;;
+ down) down ;;
+ mute) mute spr ;;
+ micm) mute mic ;;
+ getv) get volu ;;
+ getm) get mute ;;
+ geta) get both ;;
+ *) printhelp ;;
+esac
+#}}}