summaryrefslogtreecommitdiff
path: root/scripts/get-volume.sh
blob: 0696b6f5600b1d2cf7f05cdfff3c8e774bf626f9 (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
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
#!/bin/bash

# This prints a character '♫' and the percentage of the actual volume.
# ♫ = E299AB
WITH_ICONS=false

get_percentage() {
    full_db=65.25
    # -65.25 <= $db <= 0
    db=$1
    bc <<CALC scale=2
(-$db)/$full_db
CALC
}

get_icon() {
    if [ "$volStatus" == "on" ]
    then
        echo "\fr♫"
    else
        echo "\f1♫"
    fi
}

panel_volume()
{

    volStatus=$(amixer get Master | tail -n 1 | cut -d '[' -f 4 | sed 's/].*//g')
    volLevel=$(amixer get Master | tail -n 1 | cut -d '[' -f 2 | sed 's/\%].*//g')
    if $WITH_ICONS
    then
        headphone=$(amixer -c 0 contents | grep 'Headphone Jack' -A 2 | tail -n 1 | sed s/.*=//g)
    else
        headphone=""
    fi

    if $WITH_ICONS
    then
        if [ "$volStatus" == "on" ] && [ "$headphone" == "off" ];
        then
            icon="\fr ⮞"
        elif [ "$volStatus" == "on" ] && [ "$headphone" == "on" ];
        then
            icon="\fr ⮜"
        elif [ "$volStatus" == "off" ] && [ "$headphone" == "on" ];
        then
            icon="\fr ⮜"
        elif [ "$volStatus" == "off" ] && [ "$headphone" == "off" ];
        then
            icon="\fr ⮝"
        else
            icon="\f1 ⮝"
        fi
    else
        icon=$(get_icon)
    fi

    case $volLevel in
        100)
            if [ "$volStatus" == "on" ]
            then 
                echo "$icon" "\fr——————————\fr"
            else 
                echo "$icon" "\f8——————————\fr"
            fi
            ;;
        [0-9])
            if [ "$volStatus" == "on" ]
            then
                echo "$icon" "\fr—\f8—————————\fr"
            else
                echo "$icon" "\f1—\f8—————————\fr"
            fi
            ;;
        1[0-9])
            if [ "$volStatus" == "on" ]
            then
                echo "$icon" "\fr——\f8————————\fr"
            else
                echo "$icon" "\f1——\f8————————\fr"
            fi
            ;;
        2[0-9])
            if [ "$volStatus" == "on" ]
            then
                echo "$icon" "\fr———\f8———————\fr"
            else
                echo "$icon" "\f1———\f8———————\fr"
            fi
            ;;
        3[0-9])
            if [ "$volStatus" == "on" ]
            then
                echo "$icon" "\fr————\f8——————\fr"
            else
                echo "$icon" "\f1————\f8——————\fr"
            fi
            ;;
        4[0-9])
            if [ "$volStatus" == "on" ]
            then
                echo "$icon" "\fr—————\f8—————\fr"
            else
                echo "$icon" "\f1—————\f8—————\fr"
            fi
            ;;
        5[0-9])
            if [ "$volStatus" == "on" ]
            then
                echo "$icon" "\fr——————\f8————\fr"
            else
                echo "$icon" "\f1——————\f8————\fr"
            fi
            ;;
        6[0-9])
            if [ "$volStatus" == "on" ]
            then
                echo "$icon" "\fr———————\f8———\fr"
            else
                echo "$icon" "\f1———————\f8———\fr"
            fi
            ;;
        7[0-9])
            if [ "$volStatus" == "on" ]
            then
                echo "$icon" "\fr————————\f8——\fr"
            else
                echo "$icon" "\f1————————\f8——\fr"
            fi
            ;;
        8[0-9])
            if [ "$volStatus" == "on" ]
            then
                echo "$icon" "\fr——————————\f8—\fr"
            else
                echo "$icon" "\f1——————————\f8—\fr"
            fi
            ;;
        9[0-9])
            if [ "$volStatus" == "on" ]
            then
                echo "$icon" "\fr——————————\fr"
            else
                echo "$icon" "\f1——————————\fr"
            fi
            ;;
    esac
}

panel_volume