aboutsummaryrefslogtreecommitdiff
path: root/modules/volumebar
blob: f2a9fa063407db27bea991f4af9961ef75bbb3b1 (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
39
40
#!/bin/bash

# Prints out the volume percentage

# Dependencies: bc

VOLUME_WIDTH=9
VOLUME_SLIDER='⬤'
VOLUME_RAIL='◯'
VOLUME_MUTED='muted'

PREFIX=''

# If volume is >100
ALERT='!!!'

get_volume(){
        active_sink=$(pacmd list-sinks | awk '/* index:/{print $3}')
        curStatus=$(pacmd list-sinks | grep -A 15 "index: $active_sink$" | awk '/muted/{ print $2}')
        volume=$(pacmd list-sinks | grep -A 15 "index: $active_sink$" | grep 'volume:' | grep -E -v 'base volume:' | awk -F : '{print $3}' | grep -o -P '.{0,3}%'| sed s/.$// | tr -d ' ')
		slider_position=$(echo "scale=scale(1.0); x = ($volume / 100) * $VOLUME_WIDTH; scale=scale(1); x / 1" | bc)

        if [ "${curStatus}" = 'yes' ]
        then
            echo "$VOLUME_MUTED"
			exit 0
        else
			for i in $(seq 1 $VOLUME_WIDTH); do
				[[ $i = $slider_position ]] && BAR=$BAR$VOLUME_SLIDER
				[[ $i < $slider_position ]] && BAR=$BAR$VOLUME_SLIDER
				[[ $i > $slider_position ]] && BAR=$BAR$VOLUME_RAIL
			done
        fi

		[[ $volume -gt 100 ]] && PREFIX=$PREFIX$ALERT

		echo "$PREFIX$BAR"
}

get_volume