aboutsummaryrefslogtreecommitdiff
path: root/templates/.bin/get_volume
blob: 30516b0dd517d6d62db8bd2314f19398fecf1f8b (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
#!/bin/bash
# Displays the default device, volume, and mute status for i3blocks

set -a

AUDIO_MUTED_SYMBOL=
AUDIO_SYMBOL=

MIXER="default"
if amixer -D pulse info >/dev/null 2>&1 ; then
    MIXER="pulse"
fi

function print_block {
    ACTIVE=$(pacmd list-sinks | grep "state\: RUNNING" -B4 -A7 | grep "index:\|name:\|volume: front\|muted:")
    [ -z "$ACTIVE" ] && ACTIVE=$(pacmd list-sinks | grep "index:\|name:\|volume: front\|muted:" | grep -A3 '*')
    for name in INDEX NAME VOL MUTED; do
        read $name
    done < <(echo "$ACTIVE")
    INDEX=$(echo "$INDEX" | grep -o '[0-9]\+')
    VOL=$(echo "$VOL" | grep -o "[0-9]*%" | head -1 )
    VOL="${VOL%?}"

    if [[ $MUTED =~ "no" ]] ; then
        SYMB=$AUDIO_SYMBOL
    else
        SYMB=$AUDIO_MUTED_SYMBOL
    fi

    echo "<span font='FontAwesome'>${SYMB}</span> ${VOL}%"
}

print_block
while read -r EVENT; do
    print_block
done < <(pactl subscribe | stdbuf -oL grep change)