feat: optimized set-{vol,light}

This commit is contained in:
AngeD 2023-04-04 18:37:56 +02:00
parent 8c422edbb2
commit 9e438d89cd
6 changed files with 22 additions and 57 deletions

View file

@ -1,37 +1,21 @@
#!/bin/bash
set -e
#!/bin/bash -e
SINK='@DEFAULT_AUDIO_SINK@'
if [ "$1" == 'm' ]; then
wpctl set-mute "$SINK" toggle
else
VOL="$((10#$(wpctl get-volume "$SINK" | tr -dc '0-9')))"
[ -n "$1" ] && VOL="$((VOL - VOL % $1))"
CUR="$((10#$(wpctl get-volume "$SINK" | tr -dc '0-9')))"
case "${1:0:1}" in
'')
echo "$VOL"
exit
;;
'+'|'-')
VOL="$((VOL + $1))"
;;
*)
VOL="$1"
;;
'') echo "$CUR"; exit ;;
'+'|'-') CUR="$((CUR - CUR % $1 + $1))" ;;
*) CUR="$1" ;;
esac
[ "$VOL" -lt 0 ] && VOL=0
[ "$VOL" -gt 100 ] && VOL=100
wpctl set-volume "$SINK" "$VOL%"
wpctl set-mute "$SINK" 0
wpctl set-volume -l 1 "$SINK" "$CUR%"
wpctl set-mute "$SINK" 0
fi
# update sbar
kill -34 "$(cat "$HOME/.cache/pidofbar")"
if [ -t 1 ]; then
echo "$VOL"
fi