aboutsummaryrefslogtreecommitdiff
path: root/bin/status
blob: bca791a5a32f771c5e308dd1ada70561e323e32b (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
151
#!/bin/bash

# 1: last minute
cpu() {
    CPULOAD=$(cut -d " " -f 1 /proc/loadavg)
    printf " (%s%%)" "$CPULOAD"
}

mail() {
    NEWMAIL=$(expr $(ls -1 ~/mail/*/INBOX/new | wc -l) - 7)

    if [ "${NEWMAIL%% *}" -eq 0 ]; then
        printf " (%s)" "${NEWMAIL%% *}"
    else
        printf " (%s)" "${NEWMAIL%% *}"
    fi
}

battery() {
    CHARGE=$(cat /sys/class/power_supply/BAT0/capacity)
    STATUS=$(cat /sys/class/power_supply/BAT0/status)
    if [ "$STATUS" = "Charging" ]; then
        printf "  %s%%" "$CHARGE"
    else
        if [ "$CHARGE" -le 30 ]; then
            printf " %s%%" "$CHARGE"
        elif [ "$CHARGE" -le 60 ]; then
            printf " %s%%" "$CHARGE"
        elif [ "$CHARGE" -le 90 ]; then
            printf "  %s%%" "$CHARGE"
        else
            printf " %s%%" "$CHARGE"
        fi
    fi
}

volume() {
    VOL=$(amixer get Master | tail -n1 | sed -r "s/.*\[(.*)%\].*/\1/")

    if [ "$VOL" -eq 0 ]; then
        printf "🔇"
    elif [ "$VOL" -gt 0 ] && [ "$VOL" -le 33 ]; then
        printf "🔈%s%%" "$VOL"
    elif [ "$VOL" -gt 33 ] && [ "$VOL" -le 66 ]; then
        printf "🔉%s%%" "$VOL"
    else
        printf "🔊%s%%" "$VOL"
    fi
}

memory() {
    USED=$(free | awk '(NR == 2) {print $3}')
    TOTL=$(free | awk '(NR == 2) {print $2}')
    FRAC=$(tail -c 3 <<< $((${USED}00/$TOTL)))
    USED=$(free -h | awk '(NR == 2) {print $3}')

    printf " %s(%d%%)" "$USED" "$FRAC" 
}

weather() {
    curl wttr.in?format="%c+%t"
}

datetime() {
	date '+%Y-%m-%d %A %H:%M'
}

ipaddr() {
    for i in $(ip r); do echo "$i"; done | grep -A 1 src | tail -n1
}

dostatus() {
    # xsetroot -name "$VOL│$MEM│$IP│$CPU│$NML│$WTR│$TIM" 
    xsetroot -name "$VOL$BAT$MEM$IP$CPU$NML$WTR$TIM" 
    # echo "$VOL│$BAT│$MEM│$IP│$CPU│$NML│$WTR│$TIM" 
}

# signal handlers
refresh_volume() {
    VOL=$(volume)
}


refresh_battery() {
    BAT=$(battery)
}

refresh_memory() {
    MEM=$(memory)
}

refresh_ip() {
    IP=$(ipaddr)
}


refresh_cpu() {
    CPU=$(cpu)
}

refresh_mail() {
    NML=$(mail)
}

refresh_weather() {
    WTR=$(weather)
}

refresh_time() {
    TIM=$(datetime)
}

refresh_all() {
    refresh_volume
    refresh_battery
    refresh_ip
    refresh_cpu
    refresh_mail
    refresh_weather
    refresh_time
}

trap "refresh_volume"  35
trap "refresh_battery" 36
trap "refresh_memory"  37
trap "refresh_ip"      38
trap "refresh_cpu"     39
trap "refresh_weather" 40
trap "refresh_time"    41
trap "refresh_all"     42

while true # ip address
do
    sleep 2h
    refresh_ip
    refresh_weather
done &

refresh_volume
refresh_weather
refresh_ip
while true
do
    refresh_battery
    refresh_memory
    refresh_cpu
    refresh_mail
    refresh_time
    dostatus
    sleep 1m & wait $!
done