-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathVvolume
executable file
·38 lines (31 loc) · 1.19 KB
/
Vvolume
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
#!/bin/zsh
. Vglobals
function curr_volume()
{
pactl list sinks | sed -n "/$1\$/,/Volume:/s/^.*Volume: .* \([1-9][0-9]*\)%.*$/\1/p";
}
if [ "$#" -ne "1" ]; then
echo "argument must be +, -, % or number (0 mutes and unmutes)";
exit 1;
fi
default_sink="$(pactl info | sed -n 's/^Default Sink: \(.*$\)/\1/p')";
if [ "$1" = "0" ]; then
pactl set-sink-mute $default_sink toggle;
elif [ "$1" = "+" ] && [ $(($(curr_volume $default_sink) + VOLUME_DERIVATIVE_SLOPE)) -le $VOLUME_MAX ]; then
pactl set-sink-volume $default_sink +$VOLUME_DERIVATIVE_SLOPE%;
elif [ "$1" = "-" ]; then
pactl set-sink-volume $default_sink -$VOLUME_DERIVATIVE_SLOPE%;
elif [ "$1" = "%" ]; then
echo "\tDdefault sink: $default_sink";
pactl list sinks | sed -n "/$default_sink\$/,/Mute/p" | tail -n1;
current_percent=$(curr_volume $default_sink);
current_percent=$((current_percent * 100 / VOLUME_MAX));
echo "\tVolume: $current_percent%";
elif [[ "$1" =~ "^[0-9]+$" ]] && [ $1 -ge 0 ] && [ $1 -le $VOLUME_MAX ]; then
pactl set-sink-volume $default_sink $1%;
else
echo "argument must be +, -, % or number (0 mutes and unmutes)";
echo "or required volume > VOLUME_MAX, which can be set in Vglobals file";
exit 3;
fi
exit 0;