Mostly finished features
This commit is contained in:
parent
465c241cbb
commit
9757056ea7
@ -1,18 +1,28 @@
|
|||||||
#!/bin/sh
|
#!/bin/sh
|
||||||
|
|
||||||
|
# Has some undocumented features but they're functional (as far as I know)
|
||||||
|
# and system-independent. just shortcuts for me really.
|
||||||
|
|
||||||
argv0="$0"
|
argv0="$0"
|
||||||
|
|
||||||
|
! which stris >/dev/null 2>/dev/null \
|
||||||
|
&& printf "%b: Missing stris.\n" \
|
||||||
|
&& exit 1 \
|
||||||
|
|| true
|
||||||
|
|
||||||
|
VOLUME_TMP_FILE="$HOME/.volume-previous"
|
||||||
|
|
||||||
usage() {
|
usage() {
|
||||||
printf "\
|
printf "\
|
||||||
Usage: %b {absolute,help,relative,status} [ARGUMENT...]\n" "$argv0"
|
Usage: %b [function] (argument)\n" "$argv0"
|
||||||
printf "\
|
printf "\
|
||||||
Examples:
|
Functions:
|
||||||
%b absolute 0 # mute sound output
|
absolute - change sound output to absolute unit
|
||||||
%b help # print this help text
|
help - print this help output
|
||||||
%b relative 4 # increase the volume by 4 units
|
mute - toggle mute/unmute
|
||||||
%b relative -4 # decrease the volume by 4 units
|
relative - change sound output relative to current status
|
||||||
%b status # print current volume
|
status - print current sound output in system unit
|
||||||
" "$argv0" "$argv0" "$argv0" "$argv0" "$argv0"
|
"
|
||||||
printf "\
|
printf "\
|
||||||
The options are matched with [char]*. So \"%b help\"
|
The options are matched with [char]*. So \"%b help\"
|
||||||
works the same as \"%b h\".
|
works the same as \"%b h\".
|
||||||
@ -21,38 +31,77 @@ works the same as \"%b h\".
|
|||||||
exit 1
|
exit 1
|
||||||
}
|
}
|
||||||
|
|
||||||
[ -n "$1" ] || usage
|
[ -n "$1" ] \
|
||||||
|
&& argv1="$1" \
|
||||||
|
|| argv1=s
|
||||||
|
|
||||||
case "$1" in
|
case "$argv1" in
|
||||||
|
(+) # shortcut
|
||||||
|
[ -n "$2" ] && [ -z "$3" ] && stris uint "$2" \
|
||||||
|
&& "$argv0" r "$2" \
|
||||||
|
|| usage
|
||||||
|
;;
|
||||||
|
(-) # shortcut
|
||||||
|
[ -n "$2" ] && [ -z "$3" ] && stris uint "$2" \
|
||||||
|
&& "$argv0" r -"$2" \
|
||||||
|
|| usage
|
||||||
|
;;
|
||||||
(a*)
|
(a*)
|
||||||
|
[ -n "$2" ] && [ -z "$3" ] && stris int "$2" || usage
|
||||||
case "$(uname)" in
|
case "$(uname)" in
|
||||||
(NetBSD)
|
(NetBSD)
|
||||||
audioctl -w play.gain=$1 >/dev/null
|
# 9.2 STABLE 2021-07
|
||||||
|
audioctl -w play.gain=$2 >/dev/null
|
||||||
;;
|
;;
|
||||||
(*) unknown_system
|
(*) unknown_system
|
||||||
esac
|
esac
|
||||||
;;
|
exit 0 ;;
|
||||||
(h*) usage ;;
|
(h*) usage ;;
|
||||||
(r*)
|
(m*) # system independent
|
||||||
case "$(uname)" in
|
[ -z "$2" ] || usage
|
||||||
(NetBSD)
|
# restore previous volume if there is one
|
||||||
# works. 9.2 STABLE 2021-07
|
if [ -e "$VOLUME_TMP_FILE" ]; then
|
||||||
audioctl -w play.gain=$(( \
|
"$argv0" a "$(cat "$VOLUME_TMP_FILE")" \
|
||||||
$( \
|
&& rm "$VOLUME_TMP_FILE" \
|
||||||
audioctl -a \
|
&& printf "Unmuted.\n" \
|
||||||
| grep "play\.gain" \
|
&& exit 0 \
|
||||||
| cut -d '=' -f 2 \
|
|| printf "Error restoring previous volume.\n" \
|
||||||
) + $2)) >/dev/null
|
>/dev/stderr \
|
||||||
;;
|
&& exit 1
|
||||||
(*) unknown_system
|
fi
|
||||||
esac
|
|
||||||
;;
|
# otherwise, make new file with previous volume
|
||||||
|
|
||||||
|
# dd used rather than shell redirect so it's easy to determine
|
||||||
|
# whether or not the file write worked
|
||||||
|
if ! printf "%b" "$("$argv0" s)" | dd of="$VOLUME_TMP_FILE" \
|
||||||
|
2>/dev/null
|
||||||
|
then
|
||||||
|
printf "Error writing to file.\n" >/dev/stderr
|
||||||
|
false
|
||||||
|
fi
|
||||||
|
|
||||||
|
# and then of course mute
|
||||||
|
"$argv0" a 0
|
||||||
|
printf "Muted.\n"
|
||||||
|
|
||||||
|
exit 0 ;;
|
||||||
|
(r*) # system independent
|
||||||
|
[ -n "$2" ] && [ -z "$3" ] && stris int "$2" || usage
|
||||||
|
if ! newval=$(add $("$argv0" s) $2) || ! stris int "$newval"; then
|
||||||
|
printf "%b: Error finding new value for volume.\n"
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
"$argv0" a $newval
|
||||||
|
exit $? ;;
|
||||||
(s*)
|
(s*)
|
||||||
|
[ -z "$2" ] || usage
|
||||||
case "$(uname)" in
|
case "$(uname)" in
|
||||||
(NetBSD)
|
(NetBSD)
|
||||||
audioctl -a | grep "play\.gain" | cut -d '=' -f 2
|
audioctl -a | grep "play\.gain" | cut -d '=' -f 2
|
||||||
;;
|
;;
|
||||||
(*) unknown_system
|
(*) unknown_system
|
||||||
esac
|
esac
|
||||||
;;
|
exit 0 ;;
|
||||||
|
(*) usage
|
||||||
esac
|
esac
|
||||||
|
Loading…
Reference in New Issue
Block a user