aboutsummaryrefslogtreecommitdiffstats
path: root/config/herbstluftwm/panel_indicators.sh
blob: e450337209a72fb8aa0f759fad9d22a2f9c6783a (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
#!/bin/bash
battery_icon=("\ue113" "\ue114" "\ue115" "\ue116" "\ue042")
network_icon=("\ue0f1" "\ue0f2" "\ue0f3" "\ue0af")
music_icon="\ue05c"

music()
{
    # Music
    player_status=$(playerctl status)
    if [ $player_status = "Playing" ]; then
        player_artist=$(playerctl metadata artist)
        player_title=$(playerctl metadata title)
        playing="$player_title - $player_artist"

        if [ "$current" != "$playing" ] ; then
            current=$playing
            scrolling=$current
        elif [ ${#scrolling} -gt "24" ] ; then
            scrolling=${scrolling:1}
        else
            scrolling=$current
        fi

        echo -e "music\t$music_icon ${scrolling:0:24}"
    else
        echo -e "music\toff"
    fi
}

volume()
{
    # Volume
    if pgrep pulseaudio >> /dev/null ; then
        volumes=$(\
            amixer get Master | \
            grep "Front Right: Playback"\
        )
        vol=$(\
            echo $volumes | \
            sed "s/.*\[\([0-9]*\)%\].*/\1/"\
        )
        if [ -z $vol ] ; then
            echo -e "volume\toff"
        else
            echo -e "volume\t%{F$acolor_fg}\ue05d $vol%%%{F-}"
        fi
    else
        echo -e "volume\toff"
    fi
}

network()
{
    # Network
    read lo int1 int2 <<< `ip link | sed -n 's/^[0-9]: \(.*\):.*$/\1/p'`
    if iwconfig $int1 >/dev/null 2>&1; then
        wifi=$int1
        eth=$int2
    else
        wifi=$int2
        eth=$int1
    fi

    ip link show $eth | grep 'state UP' >/dev/null && int=$eth || int=$wifi

    if [ $int == $wifi ] ; then
        iwconfig=$(iwconfig $int)
        ssid=$(
            echo $iwconfig | \
            sed "s/.*ESSID:\(\".*\"\).*/\1/" | \
            sed "s/.*\(off\/any\).*/\"\1\"/" | \
            sed "s/.*\"\(.*\)\".*/\1/"
        )

        quality=$( \
            echo $iwconfig | \
            sed "s/^.*Link Quality=\([0-9]*\)\/\([0-9]*\) .*$/(\1*100)\/\2/" | \
            bc
        )

        if [ $ssid == "off/any" ] ; then
            echo -e "net\toff"
        elif [ $quality -lt 33 ] ; then
            echo -e "net\t${network_icon[0]} $ssid"
        elif [ $quality -lt 66 ] ; then
            echo -e "net\t${network_icon[1]} $ssid"
        else
            echo -e "net\t${network_icon[2]} $ssid"
        fi

    elif [ $int == $eth ] ; then
        echo -e "net\t${network_icon[3]} ethernet"
    else
        echo -e "net\toff"
    fi
}

battery()
{
    # Battery
    if $(test -e /sys/class/power_supply/BAT1) ; then

        bat_lvl=$(cat /sys/class/power_supply/BAT1/capacity)
        bat_state=$(cat /sys/class/power_supply/BAT1/status)

        if [ $bat_state == "Charging" ] ; then
            bat_status="${battery_icon[4]}"
        elif [ $bat_lvl -lt 10 ] ; then
            bat_status="${F$acolor_accent}${battery_icon[0]}${F-}"
        elif [ $bat_ -lt 33 ] ; then
            bat_status="${battery_icon[1]}"
        elif [ $bat_lvl -lt 66 ] ; then
            bat_status="${battery_icon[2]}"
        else
            bat_status="${battery_icon[3]}"
        fi

        echo -e "battery\t$bat_status $bat_lvl%%%{F-}"
    else
        echo -e "battery\toff"
    fi
}

clock()
{
    echo -e $(date +$"date\t%{F$acolor_fg}%H:%M:%S %{F$acolor_fg}(%d-%m-%Y)%{F-}")
}