nixos-configs/eww/scripts/volume.sh.bak
2023-05-28 18:05:51 -04:00

77 lines
1.7 KiB
Bash
Executable file

#!/usr/bin/env bash
VOLUME=$(pactl get-sink-volume @DEFAULT_SINK@ | grep Volume | awk '{print $5}' | tr % " ")
function icon {
if [[ $VOLUME -ge 66 ]]; then echo '󰕾'
elif [[ $VOLUME -ge 33 ]]; then echo '󰖀'
elif [[ $VOLUME -ge 1 ]]; then echo '󰕿'
else echo '󰝟'
fi
}
function level {
echo $(pactl get-sink-volume @DEFAULT_SINK@ | grep Volume | awk '{print $5}' | tr % " ")
}
function lower {
pactl set-sink-volume @DEFAULT_SINK@ -5%
update
}
function raise {
pactl set-sink-volume @DEFAULT_SINK@ +5%
update
}
function update {
eww update volume="$(get)"
~/.config/eww/scripts/osd $(icon) $(level)
}
function type_icon {
SINK=$(pactl get-default-sink)
if [[ $SINK == *'bluez_output'* ]]; then echo "󰋋"
else echo "󰓃"
fi
}
function mute_state {
STATE=$(pactl get-source-mute @DEFAULT_SOURCE@ | awk '{print $2}')
if [[ $STATE == 'no' ]]; then echo 'off'
else echo 'on'; fi
}
function mute_icon {
STATE=$(mute_state)
if [[ $STATE == 'off' ]]; then echo '󰍬'
else echo '󰍭'; fi
}
function mute_toggle {
pactl set-source-mute @DEFAULT_SOURCE@ toggle
eww update volume="$(get)"
}
function set {
pactl set-sink-volume @DEFAULT_SINK@ $1"%"
eww update volume="$(get)"
}
function get {
echo "{
\"level\": \"$(level)\",
\"icon\": \"$(icon)\",
\"type_icon\": \"$(type_icon)\",
\"mute\": {
\"state\": \"$(mute_state)\",
\"icon\": \"$(mute_icon)\"
}
}"
}
if [[ $1 == 'mute_toggle' ]]; then mute_toggle; fi
if [[ $1 == 'down' ]]; then lower; fi
if [[ $1 == 'up' ]]; then raise; fi
if [[ $1 == 'set' ]]; then set $2; fi
if [[ $1 == 'get' ]]; then get; fi