summaryrefslogtreecommitdiff
path: root/scripts/svol
diff options
context:
space:
mode:
authorSuleyman Farajli <suleyman@farajli.net>2025-06-17 22:11:51 +0400
committerSuleyman Farajli <suleyman@farajli.net>2025-06-17 22:11:51 +0400
commit4c03a6cd2038e3175e03c489845791b606c1cc06 (patch)
tree4f2943838b26d1eed5ab71ce0264aa236f968d04 /scripts/svol
parent8a4659fa081773fed35975267f01f8a7c0acf3a4 (diff)
scripts modularized
Diffstat (limited to 'scripts/svol')
-rwxr-xr-xscripts/svol56
1 files changed, 15 insertions, 41 deletions
diff --git a/scripts/svol b/scripts/svol
index 25024e7..f0765bb 100755
--- a/scripts/svol
+++ b/scripts/svol
@@ -1,5 +1,7 @@
#!/bin/sh
+. slib
+
help() {
cat << EOF
${0}: Wrapper script to change volume
@@ -12,53 +14,24 @@ options:
-t Toggle between mute and unmute
-h Print this message and exit
EOF
-}
-err() {
- for line in "${@}"; do
- echo "${line}" >&2
- done
- exit 1
+exit 0
}
-run() {
- if ! ${1} > /dev/null 2>&1; then
- err "${2}"
- fi
+check_program "pactl" "pulseaudio must be installed"
- [ -n "${3}" ] && echo "${3}"
+[ $# != 1 ] && [ $# != 2 ] && invalid_use
- slreload || echo "Warning: Failed to reload slstatus" >&2
+while getopts "i:d:s:pth" option; do
+ case "${option}" in
+ i) run --reload-status "pactl set-sink-volume @DEFAULT_SINK@ +${OPTARG}%" ;;
- exit 0
-}
+ d) run --reload-status "pactl set-sink-volume @DEFAULT_SINK@ -${OPTARG}%" ;;
-if ! command -v pactl > /dev/null 2>&1; then
- err "${0}: pulseaudio must be installed"
-fi
+ s) run --reload-status "pactl set-sink-volume @DEFAULT_SINK@ ${OPTARG}%" ;;
-if [ $# != 1 ] && [ $# != 2 ]; then
- err "${0}: Invalid usage" "Try '$0 -h' for help."
-fi
+ t) run --reload-status "pactl set-sink-mute @DEFAULT_SINK@ toggle" ;;
-while getopts "i:d:s:pth" option; do
- case "${option}" in
- i)
- run "pactl set-sink-volume @DEFAULT_SINK@ +${OPTARG}%" \
- "${0}: Failed to increase volume"
- ;;
- d)
- run "pactl set-sink-volume @DEFAULT_SINK@ -${OPTARG}%" \
- "${0}: Failed to decrease volume"
- ;;
- s)
- run "pactl set-sink-volume @DEFAULT_SINK@ ${OPTARG}%" \
- "${0}: Failed to set volume"
- ;;
- t)
- run "pactl set-sink-mute @DEFAULT_SINK@ toggle" \
- "${0}: Failed to toggle volume"
- ;;
p)
if ! pactl get-sink-volume @DEFAULT_SINK@ \
| sed -e 's,.* \([0-9][0-9]*\)%.*,\1,' | head -n1 2>/dev/null; then
@@ -67,11 +40,12 @@ while getopts "i:d:s:pth" option; do
exit 0
fi
;;
- h) help; exit 0 ;;
+ h) help ;;
- *) err "Try '${0} -h' for help" ;;
+ *) invalid_use -h ;;
esac
done
-err "${0}: Invalid usage" "Try '$0 -h' for help."
+# Unreachable
+invalid_use