blob: 374af69d9a5a44888eadb81bc849564a07e9d37c (
plain) (
blame)
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
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
|
#!/bin/sh
# This script sets the statusbar with the xsetroot command at the end. Have it
# started by ~/.xinitrc or ~/.xprofile.
# Set the deliminter character.
delim="|"
internet=false
counter=0
checkinternet() {
echo -e "GET http://google.com HTTP/1.0\n\n" | nc google.com 80 > /dev/null 2>&1
if [ $? -eq 0 ]; then
internet=true
else
internet=false
fi
}
updates() {
if [ "$internet" = true ]; then
if ! updates_arch=$(checkupdates 2> /dev/null | wc -l ); then
updates_arch=0
fi
if (( $counter % 10 == 0 )); then #this is done to add a delay and not saturate aur requests
# if ! updates_aur=$(cower -u 2> /dev/null | wc -l); then
if ! updates_aur=$(trizen -Su --aur --quiet | wc -l); then
updates_aur=0
fi
else
updates_aur=0
fi
updates=$(("$updates_arch" + "$updates_aur"))
if [ "$updates" -gt 0 ]; then
echo " Updates: $updates"
else
echo " Updates: 0"
fi
echo $delim
else
:
fi
}
tor() {
icon_enabled="ﴣ"
icon_disabled=""
status=`systemctl is-active tor.service`
if [ $status == "active" ]
then
echo "$icon_enabled $delim"
else
echo "$icon_disabled"
fi
}
wireless() {
if grep -q wlan* "/proc/net/wireless"; then
# Wifi quality percentage
percentage=$(grep "^\s*w" /proc/net/wireless | awk '{ print "", int($3 * 100 / 70)}'| xargs)
case $percentage in
100|9[0-9]|8[0-9]|7[0-9]) echo "" ;;
6[0-9]|5[0-9]|4[0-9]|3[0-9]) echo "" ;;
2[0-9]|1[0-9]|[0-9]) echo "" ;;
esac
echo $delim
else
:
fi
if [ "$internet" = true ]; then
echo ""
echo $delim
else
:
fi
}
# Here is the (big) function that outputs the appearance of the statusbar. It
# can really be broken down into many submodules which I've commented and
# explained.
status() { \
echo $(tor)
# Directs to the path of the weather script.
echo $(python $( cd "$(dirname "$0")" ; pwd -P )/weather.py)
# echo "$delim" (done in the weather script)
echo $(updates)
# Show unread mail
command -v neomutt >/dev/null 2>&1 &&
du -a ~/Mail/INBOX/new/* 2>/dev/null | wc -l | sed 's/^/: /' &&
echo "$delim"
# Get the volume of ALSA's master volume output. Show an icon if or
# not muted.
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 ' ')
if [ "${curStatus}" = 'yes' ]
then
echo " $volume%"
else
echo " $volume%"
fi
echo "$delim"
echo $(wireless)
CPU_T=$(< /sys/devices/platform/coretemp.0/hwmon/hwmon0/temp2_input)
CPU_TEMP=$(expr "$CPU_T" / 1000)
if [ "$CPU_TEMP" -ge 70 ]; then
echo " $CPU_TEMP°C"
elif [ "$CPU_TEMP" -le 10 ]; then
echo " $CPU_TEMP°C"
else
echo " $CPU_TEMP°C"
fi
echo "$delim"
# Will show all batteries with approximate icon for remaining power.
ac_adapter=$(acpi -a | cut -d' ' -f3 | cut -d- -f1)
charging=""
if [ "$ac_adapter" == "on" ]; then
echo "" #Charging
else
: #Not Charging
fi
for x in /sys/class/power_supply/BAT?/capacity;
do
case "$(cat $x)" in
100) echo "" ;;
9[0-9]) echo " $(cat $x)%" ;;
8[0-9]|7[0-9]) echo " $(cat $x)%" ;;
6[0-9]|5[0-9]) echo " $(cat $x)%" ;;
4[0-9]|3[0-9]) echo " $(cat $x)%" ;;
2[0-9]|1[0-9]) echo " $(cat $x)%" ;;
[0-9]) echo " $(cat $x)%" ;;
esac
done && echo "$delim"
# Date and time. FORMAT CORRECT NO PM
echo " $(date '+%d-%m-%y (%a) | %H:%M')"
}
while :; do
# So all that big status function was just a command that quicking gets
# what we want to be the statusbar. This xsetroot command is what sets
# it. Note that the tr command replaces newlines with spaces. This is
# to prevent some weird issues that cause significant slowing of
# everything in dwm. Note entirely sure of the cause, but again, the tr
# command easily avoids it.
xsetroot -name "$(status | tr '\n' ' ')"
checkinternet
((counter++))
# Sleep for a minute after changing the status bar before updating it
# again. Note that the `refbar` "refreshes" the statusbar by killing
# this command. Feel free to change the time interval if you want.
sleep 1s
done
|