volume
This commit is contained in:
parent
4088cb1b7b
commit
75449d26da
48
bin/volume
48
bin/volume
@ -14,13 +14,12 @@ argv0="$0"
|
||||
# `volume s` must output the current volume in integer form in whatever units
|
||||
# are being used by `volume a` on the given system.
|
||||
|
||||
VOLUME_TMP_FILE="$HOME/.volume-previous"
|
||||
! command -v stris >/dev/null 2>/dev/null \
|
||||
&& printf "%b: Missing stris.\n" "$argv0" \
|
||||
&& exit 1 \
|
||||
|| true
|
||||
|
||||
if [ "$(uname)" = "NetBSD" ]; then
|
||||
backend="NetBSD"
|
||||
elif command -v pactl >/dev/null; then
|
||||
backend="pulseaudio"
|
||||
fi
|
||||
VOLUME_TMP_FILE="$HOME/.volume-previous"
|
||||
|
||||
unknown_system(){
|
||||
printf "%s: Unknown system.\n" "$argv0" 1>&2
|
||||
@ -38,16 +37,13 @@ Functions:
|
||||
help,'' - print this help output
|
||||
mute - toggle mute/unmute
|
||||
relative - change sound output relative to current status
|
||||
status - print current sound output in system unit
|
||||
status - print current sound output in system unit \
|
||||
"
|
||||
printf "\
|
||||
The options are matched with [char]*. So \"%b help\"
|
||||
works the same as \"%b h\".
|
||||
|
||||
" "$argv0" "$argv0"
|
||||
printf "\
|
||||
The backend detected is %b.
|
||||
" "$backend"
|
||||
exit 1
|
||||
}
|
||||
|
||||
@ -61,34 +57,28 @@ case "$argv1" in
|
||||
# SYSTEM DEPENDENT
|
||||
#
|
||||
(a*)
|
||||
[ -n "$2" ] && [ -z "$3" ] || usage
|
||||
[ -n "$2" ] && [ -z "$3" ] && stris int "$2" || usage
|
||||
|
||||
case "$backend" in
|
||||
NetBSD)
|
||||
if [ "$(uname)" = "NetBSD" ]; then
|
||||
# NetBSD 9.2 STABLE 2021-07
|
||||
audioctl -w play.gain=$2 >/dev/null
|
||||
;;
|
||||
|
||||
pulseaudio)
|
||||
elif command -v pactl >/dev/null; then
|
||||
# pactl 15.0 compiled+linked with libpulse 15.0.0
|
||||
pactl set-sink-volume @DEFAULT_SINK@ $2%
|
||||
;;
|
||||
|
||||
*) unknown_system
|
||||
esac
|
||||
else unknown_system; fi
|
||||
exit 0 ;;
|
||||
(s*)
|
||||
[ -z "$2" ] || usage
|
||||
|
||||
case "$backend" in
|
||||
NetBSD)
|
||||
if [ "$(uname)" = "NetBSD" ]; then
|
||||
# hacky
|
||||
audioctl -a \
|
||||
| grep "play\.gain" \
|
||||
| cut -d '=' -f 2
|
||||
;;
|
||||
|
||||
pulseaudio)
|
||||
elif command -v pactl >/dev/null; then
|
||||
# really hacky, gets the job done
|
||||
# gets the volume % of Lchan specifically
|
||||
pactl get-sink-volume @DEFAULT_SINK@ \
|
||||
@ -96,21 +86,19 @@ case "$argv1" in
|
||||
| cut -d '/' -f 2 \
|
||||
| xargs echo \
|
||||
| sed s/'%'//
|
||||
;;
|
||||
|
||||
*) unknown_system ;;
|
||||
esac
|
||||
else unknown_system; fi
|
||||
exit 0 ;;
|
||||
#
|
||||
# SYSTEM independent
|
||||
#
|
||||
(+)
|
||||
[ -n "$2" ] && [ -z "$3" ] \
|
||||
[ -n "$2" ] && [ -z "$3" ] && stris uint "$2" \
|
||||
&& "$argv0" r "$2" \
|
||||
|| usage
|
||||
;;
|
||||
(-)
|
||||
[ -n "$2" ] && [ -z "$3" ] \
|
||||
[ -n "$2" ] && [ -z "$3" ] && stris uint "$2" \
|
||||
&& "$argv0" r -"$2" \
|
||||
|| usage
|
||||
;;
|
||||
@ -144,14 +132,14 @@ case "$argv1" in
|
||||
|
||||
exit 0 ;;
|
||||
(r*)
|
||||
[ -n "$2" ] && [ -z "$3" ] \
|
||||
[ -n "$2" ] && [ -z "$3" ] && stris int "$2" \
|
||||
|| usage
|
||||
|
||||
if ! newval="$(printf "%s %s + p\n" "$("$argv0" s)" "$(printf "%s\n" "$2" | sed 's/^-/_/')" | dc)"; then
|
||||
if ! newval=$(add $("$argv0" s) $2) || ! stris int "$newval"; then
|
||||
printf "%b: Error finding new value for volume.\n" "$argv0"
|
||||
exit 1
|
||||
fi
|
||||
"$argv0" a "$newval"
|
||||
"$argv0" a $newval
|
||||
exit $? ;;
|
||||
(h*) usage ;;
|
||||
(*) usage ;;
|
||||
|
54
man/volume.1
Normal file
54
man/volume.1
Normal file
@ -0,0 +1,54 @@
|
||||
.TH VOLUME 1
|
||||
|
||||
.SH NAME
|
||||
|
||||
volume \(en change the current audio volume
|
||||
|
||||
.SH SYNOPSIS
|
||||
|
||||
volume {function} [operand]
|
||||
|
||||
.SH DESCRIPTION
|
||||
|
||||
Volume provides a common interface for elementary configuration of the
|
||||
current system audio volume.
|
||||
.PP
|
||||
Volume is not a replacement for the system-specific audio interface.
|
||||
|
||||
.SH FUNCTIONS
|
||||
|
||||
.SS +
|
||||
|
||||
Shortcut to "volume r ".
|
||||
|
||||
.SS -
|
||||
|
||||
Shortcut to "volume r -".
|
||||
|
||||
.SS a
|
||||
|
||||
Change sound output to absolute unit.
|
||||
|
||||
.SS h
|
||||
|
||||
Print help output.
|
||||
|
||||
.SS m
|
||||
|
||||
Toggle audio mute.
|
||||
|
||||
.SS r
|
||||
|
||||
Change sound output relative to current status.
|
||||
|
||||
.SS s
|
||||
|
||||
Print current sound output level in system unit.
|
||||
|
||||
.SH BUGS
|
||||
|
||||
Many.
|
||||
|
||||
.SH COPYRIGHT
|
||||
|
||||
Public domain.
|
Loading…
Reference in New Issue
Block a user