summaryrefslogtreecommitdiff
path: root/.local/bin/statusbar/volume
blob: 2766ed238cc5d1ef3414944c85015d12c65e54b4 (plain)
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
38
#!/bin/sh

# Prints the current volume or 🔇 if muted. Uses PulseAudio by default,
# uncomment the ALSA lines if you remove PulseAudio.

case $BLOCK_BUTTON in
	# 1) setsid -f "$TERMINAL" -e alsamixer ;;
	# 2) amixer sset Master toggle ;;
	# 4) amixer sset Master 5%+ >/dev/null 2>/dev/null ;;
	# 5) amixer sset Master 5%- >/dev/null 2>/dev/null ;;
	1) setsid -f "$TERMINAL" -e pulsemixer ;;
	2) pamixer -t ;;
	4) pamixer --allow-boost -i 1 ;;
	5) pamixer --allow-boost -d 1 ;;
	3) notify-send "📢 Volume module" "\- Shows volume 🔊, 🔇 if muted.
- Middle click to mute.
- Scroll to change." ;;
	6) "$TERMINAL" -e "$EDITOR" "$0" ;;
esac

volstat="$(pactl list sinks)"
# volstat="$(amixer get Master)" # ALSA only equivalent.

echo "$volstat" | grep -q "Mute: yes" && printf "🔇\\n" && exit
# echo "$volstat" | grep "\[off\]" >/dev/null && printf "🔇\\n" && exit # ALSA

vol="$(echo "$volstat" | grep '[0-9]\+%' | sed "s,.* \([0-9]\+\)%.*,\1,;1q")"
# vol=$(echo "$volstat" | grep -o "\[[0-9]\+%\]" | sed "s/[^0-9]*//g;1q") # ALSA

if [ "$vol" -gt "70" ]; then
	icon="🔊"
elif [ "$vol" -lt "30" ]; then
	icon="🔈"
else
	icon="🔉"
fi

printf "%s%s%%\\n" "$icon" "$vol"