added some corrections to bin/statusbar; the xterm font size is
[home.git] / bin / statusbar
blob6e1a7b292942de0a01ababb68215aeb5f99f8360
1 #!/bin/sh
2 # $Id: bin/statusbar,v 1.5 2016/12/18 11:09:10 fstef Exp $
4 # dzen status bar configuration file
7 # ------------------------------------------------------------------------------
8 # Copywhat (?) 2016 stefano ferro <fstef@cryptolab.net>
10 # This work is protected by the Berne Convention but nobody can tell us
11 # what we can do and what we can't, so we don't care.
12 # Anybody caught use, copy, hacking, and distribute this work for any
13 # purpose, or otherwise experience it, without our permission.
14 # Credit the creator of this work is a matter of ethics, not a matter
15 # of law, so is up to you.
17 # THE WORK IS PROVIDED "AS IS" AND YOU USE IT AT YOUR OWN RISK.
18 # ------------------------------------------------------------------------------
20 # set defaults values
21 XPOINT=0
22 WIDTH=1366
23 #WIDTH=1340
24 HEIGHT=16
25 FG="#5f5a60"
26 BG="#080808"
27 FONT="-*-terminus-medium-r-*-*-14-*-*-*-*-*-*-*"
29 # set colors
30 RED="^fg(red)^bg()"
31 GREEN="^fg(green)^bg()"
32 YELLOW="^fg(yellow)^bg()"
33 WHITE="^fg(#ffdead)^bg()"
34 ICOLOR="^fg(#ff7f50)"
35 CHARC="^fg(#008b8b)^bg()"
36 #CHARC="^fg(#36454f)^bg()"
37 NC="^fg()^bg()"
40 print_delim() {
41 echo -n " ${CHARC}::${NC} "
43 print_date() {
44 FORMAT="%a, %b %d %H:%M:%S"
45 DATE=$(date "+${FORMAT}")
46 echo -n "${WHITE}${DATE}${NC} "
49 print_volume() {
50 VOLSTAT=$(mixerctl outputs.master.mute | sed -e 's/outputs.master.mute=//')
51 # VOL=$(mixerctl outputs.master | sed -e 's/outputs.master=//')
52 if [ $VOLSTAT == "off" ]; then
53 echo -n "${ICOLOR}>>>${NC}"
54 else
55 echo -n "${ICOLOR}<<<${NC}"
59 print_mail() {
60 NMAIL=$(new | awk '/total/ {print $2}' | sed -e 's/\.//')
61 if [[ $NMAIL -eq 0 ]]; then
62 echo -n "@"
63 else
64 echo -n "${ICOLOR}@${NC}${NMAIL}"
68 print_temp() {
69 TMP=$(sysctl | grep acpitz | sed -e 's/hw\.sensors\.acpitz0\.temp0=//' -e 's/\.00 degC (zone temperature)//')
70 if [ $TMP -lt 75 ]; then
71 echo -n "t:${TMP}°"
72 else
73 echo -n "t:${RED}${TMP}°${NC}"
77 print_fan() {
78 FAN=$(sysctl | grep fan | sed -e 's/hw.sensors.acpithinkpad0.fan0=//' -e 's/ RPM/rpm/')
79 echo -n "fan:${FAN}"
82 print_mem() {
83 MEM=$(/usr/bin/top | grep Free: | cut -d " " -f6)
84 echo -n "mem:${MEM}"
87 #print_eth() {
88 # STATUS=$(ifconfig em0 | grep "status" | awk '{$1=$1}{ print $2}')
89 # case $STATUS in
90 # active)
91 # echo -n "${GREEN}||${RED}||${NC}"
92 # ;;
93 # *)
94 # echo -n "||||"
95 # ;;
96 # esac
99 #print_iwn() {
100 # LABEL=$(ifconfig iwn0 | awk '/status/ {print $2}')
101 # case $LABEL in
102 # active)
103 # echo -n "${GREEN}||${RED}||${NC}"
104 # ;;
105 # *)
106 # echo -n "||||"
107 # ;;
108 # esac
110 print_lan() {
111 STATUS=$(ifconfig em0 | grep "status" | awk '{$1=$1}{ print $2}')
112 LABEL=$(ifconfig iwn0 | awk '/status/ {print $2}')
113 if [[ $STATUS = "active" ]]; then
114 echo -n "${GREEN}||${RED}||${NC}"
115 elif [[ $LABEL = "active" ]]; then
116 echo -n "${GREEN}||${RED}||${NC}"
117 else
118 echo -n "||||"
122 #_print_cpu() {
123 # typeset -R4 _1=${1} _2=${2} _3=${3} _4=${4} _5=${5}
124 # echo -n "CPU:${_1}% User${_2}% Nice${_3}% Sys${_4}% Int${_5}% Idle "
127 #print_cpu() {
128 # OUT=""
129 # # iostat prints each column justified to 3 chars, so if one counter
130 # # is 100, it jams up agains the preceeding one. sort this out.
131 # while [ "${1}x" != "x" ]; do
132 # if [ ${1} -gt 99 ]; then
133 # OUT="$OUT ${1%100} 100"
134 # else
135 # OUT="$OUT ${1}"
136 # fi
137 # shift;
138 # done
139 # _print_cpu $OUT
143 #print_apm() {
144 # BAT_STATUS=$1
145 # BAT_LEVEL=$2
146 # AC_STATUS=$3
147 # if [ $AC_STATUS -ne 255 -o $BAT_STATUS -lt 4 ]; then
149 # if [ $AC_STATUS -eq 0 ]; then
150 # if [ $BAT_STATUS -eq 0 ]; then
151 # echo -n " ${GREEN}^i($BATF)${NC}${BAT_LEVEL}% "
152 # fi
153 # if [ $BAT_STATUS -eq 1 ]; then
154 # echo -n " ${YELLOW}^i($BATL)${NC}${BAT_LEVEL}% "
155 # fi
156 # if [ $BAT_STATUS -eq 2 ]; then
157 # echo -n " ${RED}^i($BATE)${NC}${BAT_LEVEL}% "
158 # fi
159 # fi
160 # if [ $AC_STATUS -eq 1 ]; then
162 # if [ $BAT_STATUS -eq 0 ]; then
163 # echo -n " ${GREEN}^i($ACI)${NC}${BAT_LEVEL}% "
164 # fi
165 # if [ $BAT_STATUS -eq 1 ]; then
166 # echo -n " ${YELLOW}^i($ACI)${NC}${BAT_LEVEL}% "
167 # fi
168 # if [ $BAT_STATUS -eq 2 ]; then
169 # echo -n " ${RED}^i($ACI)${NC}${BAT_LEVEL}% "
170 # fi
171 # if [ $BAT_STATUS -eq 3 ]; then
172 # echo -n " battery charging ${GREEN}${BAT_LEVEL}%${NC} "
173 # fi
174 # fi
175 # fi
178 print_apm() {
179 BAT_STATUS=$1
180 BAT_LEVEL=$2
181 AC_STATUS=$3
183 if [ $AC_STATUS -ne 255 -o $BAT_STATUS -lt 4 ]; then
184 if [ $AC_STATUS -eq 0 ]; then
186 if [ $BAT_STATUS -eq 0 ]; then
187 echo -n "${GREEN}[${NC}${BAT_LEVEL}%${GREEN}]${NC}"
189 if [ $BAT_STATUS -eq 1 ]; then
190 echo -n "${YELLOW}[${NC}${BAT_LEVEL}%${YELLOW}]${NC}"
192 if [ $BAT_STATUS -eq 2 ]; then
193 echo -n "${RED}[${NC}${BAT_LEVEL}%${RED}]${NC}"
195 if [ $BAT_STATUS -eq 3 ]; then
196 echo -n "battery charging ${GREEN}${BAT_LEVEL}%${NC}"
199 else
200 case $AC_STATUS in
202 AC_STRING="${ICOLOR}+${NC}"
205 AC_STRING="backup +"
208 AC_STRING=""
210 esac;
211 case $BAT_STATUS in
213 BAT_STRING="no battery"
215 [0-3])
216 BAT_STRING="${BAT_LEVEL}%"
219 BAT_STRING="battery unknown"
221 esac;
223 FULL="${AC_STRING}${BAT_STRING}"
224 if [ "$FULL" != "" ]; then
225 echo -n "[$FULL]"
231 print_cpuspeed() {
232 CPU_SPEED=$(/sbin/sysctl hw.cpuspeed | cut -d "=" -f2)
233 echo -n "cpu:${CPU_SPEED}MHz"
237 while true; do
238 #while :; do
239 # /usr/sbin/iostat -C -c 1 |&
240 # PID="$1"
241 # APM_DATA=""
242 # I=0
243 # trap "kill $PID; exit" TERM
244 # while read -p; do
245 # if [ $(( ${I} % 1 )) -eq 0 ]; then
246 APM_DATA=$(/usr/sbin/apm -alb)
247 # fi
248 # if [ $I -ge 2 ]; then
249 print_delim
250 print_mem $MEM
251 # print_cpu $REPLY
252 print_delim
253 print_cpuspeed
254 print_delim
255 print_temp
256 print_delim
257 print_fan
258 print_delim
259 # print_eth
260 # print_iwn
261 print_lan
262 print_delim
263 print_mail
264 print_delim
265 print_apm $APM_DATA
266 print_delim
267 print_volume
268 print_delim
269 print_date
270 echo ""
271 # fi
272 # I=$(( ( ${I} + 1 ) % 22 ));
273 # done
275 sleep 1
277 done | dzen2 -h $HEIGHT -ta r -x $XPOINT -w $WIDTH -h 14 -fg $FG -bg $BG -fn $FONT