#!/bin/sh # calculate average of two integers (for ALSA) average () { echo "$(( $(( $1 + $2 )) / 2 ))$" } # print error message printerror () { echo "$1 is not a recognized command or flag" } # if pulseaudio pulsesv () { 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\]/' ;; *) printerror "$1" ;; esac } # if alsa alsasv () { 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]*\%\]' | cut -d' ' -f6 | sed 's/\[//;s/\]//g' ;; "getm" | "-g") amixer sget Master | grep '\[o[fn]' | cut -d' ' -f8 | head -1 ;; *) printerror "$1" ;; esac } #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." && exit for i in $@; do pgrep -x pulseaudio >/dev/null && pulsesv $1 || alsasv $1 pgrep -x dwmblocks >/dev/null && pkill -RTMIN+10 dwmblocks pgrep -x dwmbar >/dev/null && dwmbar-signal volume done