-
Notifications
You must be signed in to change notification settings - Fork 0
/
dzen.sh
executable file
·235 lines (187 loc) · 6.82 KB
/
dzen.sh
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
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
#!/bin/zsh
#
# Dzen statusbar, compiled from various sources
# Requires weather.com key and mocp
##################################################################
# Configuration
##################################################################
# Dzen's font
MAIN_COLOR="#ff5f00"
DZENFNT="-*-snap-*-*-*-*-12-*-*-*-*-*-*-*"
# Dzen's background colour
DZENBG='#262626'
# Dzen's forground colour
DZENFG='#999999'
# Dzen's X position
DZENX=0
#DZENX=600
# Dzen's Y posit
DZENY=0
# Dzen's width
DZENWIDTH=766
# Dzen's alignment (l=left c=center r=right)
DZENALIGN=r
# Gauge background colour
GAUGEBG='#323232'
# Gauge foreground colour
GAUGEFG=$MAIN_COLOR
# Path to your Dzen icons
ICONPATH=/home/pielgrzym/.xmonad/icons
# Network interface
INTERFACE=eth0
# Sound device for volume control
SNDDEVICE=Master
# Date formating
# Main loop interval in seconds
SLEEP=1
# Function calling intervals in seconds
DATEIVAL=20
CPUTEMPIVAL=60
VOLUMEIVAL=1
BATIVAL=5
WIFIIVAL=5
##################################################################
# battery >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
fbattery() {
GW=30 # width of the gauge
GFG='#999' # color of the gauge
GH=7 # height of the gauge
GBG='#333' # color of gauge background
STATEFILE='/proc/acpi/battery/BAT0/state' # battery's state file
INFOFILE='/proc/acpi/battery/BAT0/info' # battery's info file
LOWBAT=3 # percentage of battery life marked as low
LOWCOL='#ff4747' # color when battery is low
PREBAR="^i(${ICONPATH}/bat_full_01.xbm)" # caption (also icons are possible)
# look up battery's data
BAT_FULL=`cat $INFOFILE|grep design|line|cut -d " " -f 11`
STATUS=`cat $STATEFILE|grep charging|cut -d " " -f 12`
RCAP=`cat $STATEFILE|grep remaining|cut -d " " -f 8`
# calculate remaining power
RPERCT=`expr $RCAP \* 100`;
RPERC=`expr $RPERCT / $BAT_FULL`
# draw the bar and pipe everything into dzen
if [ $RPERC -le $LOWBAT ]; then
GFG=$LOWCOL
aplay ~/var/bateria.wav
fi
echo -n "$PREBAR $RPERC% "
echo $RPERC | gdbar -s o -ss 1 -sw 1 -h $GH -w $GW -fg $GFG -bg $GBG
}
# wifi
##################################################################
fwifi() {
WIFI_STATE=`cat /sys/class/net/wlan0/operstate`
WIFI_SIGNAL=`cat /sys/class/net/wlan0/wireless/link`
if [[ $WIFI_STATE == "up" ]]; then
echo -n "^i($ICONPATH/wifi_02.xbm) "
echo $WIFI_SIGNAL | gdbar -s o -ss 1 -sw 1 -w 30 -h 7 -fg $GAUGEFG -bg $GAUGEBG
fi
}
# Time and date
##################################################################
fdate() {
date +"%d.%m.%Y"
}
ftime() {
date +"%H:%M"
}
##################################################################
# CPU use
##################################################################
fcpu() {
gcpubar -c 5 -i 0.1 -s o -ss 1 -sw 1 -fg $GAUGEFG -bg $GAUGEBG -h 7 -w 30 | tail -1
}
##################################################################
# CPU temp
##################################################################
fcputemp() {
print -n ${(@)$(</proc/acpi/thermal_zone/TZ00/temperature)[2,3]}
}
##################################################################
# HD partitions used and free space
##################################################################
#fhd() {
# Todo
#}
##################################################################
# Network
##################################################################
# Here we remember the previous rx/tx counts
RXB=`cat /sys/class/net/${INTERFACE}/statistics/rx_bytes`
TXB=`cat /sys/class/net/${INTERFACE}/statistics/tx_bytes`
# MOCP song info and control
##################################################################
#fmusic() {
#artist=`mocp -i | grep 'Artist' | cut -c 8-`
#songtitle=`mocp -i | grep 'SongTitle' | cut -c 11-`
#totaltime=`mocp -i | grep 'TotalTime' | cut -c 12-`
#currenttime=`mocp -i | grep 'CurrentTime' | cut -c 14-`
#state=`mocp -i | grep 'State' | cut -c 8-`
#print -n "$(echo $artist -$songtitle [)$(echo $currenttime/$totaltime] [)$(echo $state])"
#}
# For Creative Audigy 2 ZS
fvolume() {
percentage=`amixer sget Master | sed -ne 's/^.*Mono: .*\[\([0-9]*\)%\].*$/\1/p'`
print -n "$(echo $percentage | gdbar -s v -fg $GAUGEFG -bg $GAUGEBG -h 7 -w 6)"
}
# Command to toggle pause/unpause
TOGGLE="mocp -G"
# Command to increase the volume
CI="amixer -c0 sset Master 2dB+ >/dev/null"
# Command to decrease the volume
CD="amixer -c0 sset Master 2dB- >/dev/null"
##################################################################
# Main function
##################################################################
DATECOUNTER=0;CPUTEMPCOUNTER=0;VOLUMECOUNTER=0;BATTCOUNTER=0;WIFICOUNTER=0;
# Execute everything once
PDATE=$(fdate)
PTIME=$(ftime)
PCPU=$(fcpu)
PCPUTEMP=$(fcputemp)
PVOLUME=$(fvolume)
#BATTERY=$(fbattery)
#WIFI=$(fwifi)
# Main loop
while :; do
PCPU=$(fcpu)
#if [ $WIFICOUNTER -ge $WIFIIVAL ]; then
#WIFI=$(fwifi)
#WIFICOUNTER=0
#fi
#if [ $BATTCOUNTER -ge $BATIVAL ]; then
#BATTERY=$(fbattery)
#BATTCOUNTER=0
#fi
if [ $DATECOUNTER -ge $DATEIVAL ]; then
PDATE=$(fdate)
PTIME=$(ftime)
DATECOUNTER=0
fi
if [ $CPUTEMPCOUNTER -ge $CPUTEMPIVAL ]; then
PCPUTEMP=$(fcputemp)
CPUTEMPCOUNTER=0
fi
if [ $VOLUMECOUNTER -ge $VOLUMEIVAL ]; then
PVOLUME=$(fvolume)
VOLUMECOUNTER=0
fi
# Get new rx/tx counts
RXBN=`cat /sys/class/net/${INTERFACE}/statistics/rx_bytes`
TXBN=`cat /sys/class/net/${INTERFACE}/statistics/tx_bytes`
# Calculate the rates
# format the values to 4 digit fields
RXR=$(printf "%d\n" $(echo "($RXBN - $RXB) / 1024/${SLEEP}" | bc))
TXR=$(printf "%d\n" $(echo "($TXBN - $TXB) / 1024/${SLEEP}" | bc))
# Print out
echo " ^fg($MAIN_COLOR)^p(0)^i(${ICONPATH}/cpu.xbm) ^fg()${PCPU} ^fg(#80AA83)^i(${ICONPATH}/temp.xbm) ^fg()${PCPUTEMP} ^fg(#80AA83)^p(0)^i(${ICONPATH}/net_down_02.xbm)^fg()${RXR}kB/s ^fg(orange3)^p(0)^i(${ICONPATH}/net_up_02.xbm)^fg()${TXR}kB/s^fg() ^fg() ^fg($MAIN_COLOR)^p(0)^i(${ICONPATH}/spkr_01.xbm) ${PVOLUME} ^fg(#FFFFFF)${PDATE} ^bg($MAIN_COLOR) ${PTIME} "
# Reset old rates
RXB=$RXBN; TXB=$TXBN
DATECOUNTER=$((DATECOUNTER+1))
CPUTEMPCOUNTER=$((CPUTEMPCOUNTER+1))
VOLUMECOUNTER=$((VOLUMECOUNTER+1))
#BATTCOUNTER=$((BATTCOUNTER+1))
#WIFICOUNTER=$((WIFICOUNTER+1))
sleep $SLEEP
# Pass it to dzen
done | dzen2 -xs 2 -bg $DZENBG -fg $DZENFG -x $DZENX -y $DZENY -ta $DZENALIGN -h 14 -p -fn $DZENFNT -dock