config_sway/bin/sway_volume

69 lines
1.4 KiB
Bash
Executable file

#!/bin/bash
source $HOME/.config/sway/bin/sway_helpers
SINK=$(pactl info | grep "Default Sink" | cut -d ' ' -f 3)
ICON_PATH=$HOME/.local/share/icons/Tela-circle-dark/16/actions
NOTIFY_APP="dunstify -a \"Volume\" -r 97"
function notify() {
VOLUME=$(pactl list sinks | grep "Name: $SINK" -A 8 | grep -oE '[0-9]*%' | head -n 1 | sed 's/%//')
MUTE=$(pactl list sinks | grep "Name: $SINK" -A 8 | grep 'Mute:' | cut -d " " -f 2)
echo $MUTE
ICON=""
if [ "$MUTE" = "yes" ]; then
ICON=$ICON_PATH/audio-volume-muted.svg
elif [ $VOLUME -le 33 ]; then
ICON=$ICON_PATH/audio-volume-low.svg
elif [ $VOLUME -le 67 ]; then
ICON=$ICON_PATH/audio-volume-medium.svg
else
ICON=$ICON_PATH/audio-volume-high.svg
fi
$NOTIFY_APP -i $ICON -a "Volume" "$VOLUME Mute: $MUTE"
}
APP="pavucontrol"
SOUND=$HOME/.config/sway/bin/drip.ogg
## helpers
function _toggle() {
a=$1
if [ $(pgrep $a) ]; then
killall $a
else
$a &> /dev/null &
fi
}
## main
if [ -z "$SINK" ]; then
_log VOLUME ERROR args: $*
exit 1
fi
case $1 in
d*)
pactl set-sink-volume $SINK -5%
paplay $SOUND &
notify
;;
i*)
pactl set-sink-volume $SINK +5%
paplay $SOUND &
notify
;;
m*)
pactl set-sink-mute $SINK toggle
paplay $SOUND &
notify
;;
gui)
_check_app $APP
_toggle $APP
;;
*)
echo "invalid command: \"$1\""
echo "arguments: [decrease|increase|mute|gui]"
;;
esac