feat: simplify vol, light and am
This commit is contained in:
parent
57243c81fa
commit
47c176f3bc
3 changed files with 46 additions and 66 deletions
|
@ -1,42 +1,34 @@
|
|||
#!/bin/bash -e
|
||||
|
||||
NOTIFY='notify-send -t 1000 -a changeVolume -u low'
|
||||
NOTIFYVOL="$NOTIFY -i audio-volume-high"
|
||||
|
||||
SINK='@DEFAULT_AUDIO_SINK@'
|
||||
WPCUR="$(wpctl get-volume "$SINK")"
|
||||
CUR="$((10#$(tr -dc '0-9' <<< "$WPCUR")))"
|
||||
NOTIFY=(notify-send -t 1000 -a "$(basename "$0")" -u low)
|
||||
|
||||
grep -q MUTED <<< "$WPCUR" && MUTE=1 || MUTE=0
|
||||
|
||||
if [ "$1" == 'm' ]; then
|
||||
if [ "$MUTE" = 1 ]; then
|
||||
wpctl set-mute "$SINK" 0
|
||||
$NOTIFYVOL -h string:synchronous:vol -h int:value:"$CUR" "$CUR%"
|
||||
function update_vol() {
|
||||
if [[ "$1" =~ ^(-|\+)* ]]; then
|
||||
CUR="$((CUR - CUR % $1 + $1))"
|
||||
[ "$CUR" -lt 0 ] && CUR=0
|
||||
[ "$CUR" -gt 150 ] && CUR=150
|
||||
else
|
||||
wpctl set-mute "$SINK" 1
|
||||
$NOTIFY -i audio-volume-muted -h string:synchronous:vol "Mute"
|
||||
CUR="$1"
|
||||
fi
|
||||
else
|
||||
case "${1:0:1}" in
|
||||
'')
|
||||
echo "$CUR"; exit
|
||||
;;
|
||||
'+'|'-')
|
||||
CUR="$((CUR - CUR % $1 + $1))"
|
||||
[ "$CUR" -lt 0 ] && CUR=0
|
||||
[ "$CUR" -gt 150 ] && CUR=150
|
||||
;;
|
||||
*)
|
||||
CUR="$1"
|
||||
;;
|
||||
esac
|
||||
|
||||
wpctl set-volume "$SINK" "$CUR%"
|
||||
if [ "$MUTE" = 1 ]; then
|
||||
wpctl set-mute "$SINK" 0
|
||||
}
|
||||
|
||||
read -r _ CUR MUTE < <(wpctl get-volume "$SINK")
|
||||
CUR="${CUR/#0/}"; CUR="${CUR/#./}"
|
||||
|
||||
if [ -z "$1" ]; then
|
||||
echo "$CUR"
|
||||
exit
|
||||
elif [ "$1" == 'm' ] && [ -z "$MUTE" ]; then
|
||||
wpctl set-mute "$SINK" 1
|
||||
"${NOTIFY[@]}" -i audio-volume-muted -h string:synchronous:vol "Mute"
|
||||
else
|
||||
if [[ "$1" =~ [0-9] ]]; then
|
||||
update_vol "$1"
|
||||
fi
|
||||
$NOTIFYVOL -h string:synchronous:vol -h int:value:"$CUR" "$CUR%"
|
||||
[ -n "$MUTE" ] && wpctl set-mute "$SINK" 0
|
||||
"${NOTIFY[@]}" -h string:synchronous:vol -h int:value:"$CUR" "$CUR%"
|
||||
fi
|
||||
|
||||
# update sbar
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue