blob: 1b1cc0d27474c33c92d33c69c9bdce2e6e854357 (
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
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
|
#!/bin/bash
hc() { "${herbstclient_command[@]:-herbstclient}" "$@" ;}
monitor=${1:-0}
geometry=( $(herbstclient monitor_rect "$monitor") )
if [ -z "$geometry" ] ;then
echo "Invalid monitor $monitor"
exit 1
fi
# geometry has the format W H X Y
x=${geometry[0]}
y=${geometry[1]}
panel_width=${geometry[2]}
add_alpha_channel(){
echo "$1" | \
sed "s/.*#\([0-9a-fA-F]*\).*/#ff\1/"
}
panel_height=$2
light=$(add_alpha_channel $3)
llight=$(add_alpha_channel $4)
accent=$(add_alpha_channel $5)
ldark=$(add_alpha_channel $6)
dark=$(add_alpha_channel $7)
font="-*-fixed-medium-*-*-*-14-*-*-*-*-*-*-*"
#font=""
selected_bg=$accent
normal_bg=$dark
selected_txt=$dark
normal_txt=$light
inactive_txt=$llight
hc pad $monitor $panel_height
if awk -Wv 2>/dev/null | head -1 | grep -q '^mawk'; then
# mawk needs "-W interactive" to line-buffer stdout correctly
# http://bugs.debian.org/cgi-bin/bugreport.cgi?bug=593504
uniq_linebuffered() {
awk -W interactive '$0 != l { print ; l=$0 ; fflush(); }' "$@"
}
else
# other awk versions (e.g. gawk) issue a warning with "-W interactive", so
# we don't want to use it there.
uniq_linebuffered() {
awk '$0 != l { print ; l=$0 ; fflush(); }' "$@"
}
fi
{
### Event generator ###
# <eventname>\t<data> [...]
# e.g.
# date ^fg(#efefef)18:33^fg(#909090), 2013-10-^fg(#efefef)29
while true ; do
# Volume
if pgrep pulseaudio > /dev/null ; then
volumes=$(\
amixer get Master | \
grep Front\
)
vol=$(\
echo $volumes | \
sed "s/.*\[\([0-9]*\)%\].*/\1/"\
)
if [ -z $vol ] ; then
echo -e "volume\toff"
elif [ $vol -le 0 ] ; then
echo -e "volume\t%{F$normal_txt}Volume muted"
else
echo -e "volume\t%{F$normal_txt}Volume: $vol%%%{F-}"
fi
else
echo -e "volume\toff"
fi
# Network
iwconfig=$(iwconfig wlp3s0)
if [ -z $iwconfig ] ; then
echo -e "wireless\toff"
else
ssid=$(\
echo $iwconfig | \
sed "s/.*ESSID:\(\".*\"\).*/\1/" | \
sed "s/.*\(off\/any\).*/\"\1\"/" | \
sed "s/.*\"\(.*\)\".*/\1/"\
)
if [ $ssid = "off/any" ] ; then
ifconf=$
echo -e "wireless\t%{F$normal_txt}Wlan: No connection%{F-}"
else
IFS=',' read -a quality_info <<< $(\
echo $iwconfig | \
sed "s/.*Link Quality=\([0-9]*\)\/\([0-9]*\).*/\1,\2/"\
)
cur_qual=${quality_info[0]}
max_qual=${quality_info[1]}
quality_p=$(echo "$cur_qual*100/$max_qual" | bc)
echo -e "wireless\t%{F$normal_txt}Wlan: $quality_p%% %{F$inactive_txt}($ssid)%{F-}"
fi
fi
# Battery
IFS=' ' read -a batinfo <<< $(acpi -b)
if [ -z $batinfo ] ; then
echo -e "battery\toff"
else
charge=$(echo ${batinfo[3]} | tr -d '%,')
if [ $charge -lt 15 ] ; then
bat_color=$accent
else
bat_color=$normal_txt
fi
state=$(echo ${batinfo[2]} | tr -d ',')
remaining=$(echo ${batinfo[4]})
echo -e "battery\t%{F$normal_txt}$state: %{F$bat_color}$charge%{F$normal_txt}%% %{F$inactive_txt}($remaining)%{F-}"
fi
# Time
echo -e $(date +$"date\t%{F$normal_txt}%H:%M:%S %{F$inactive_txt}(%d-%m-%Y)%{F-}")
sleep 1 || break
done > >(uniq_linebuffered) &
childpid=$!
hc --idle
kill $childpid
} 2> /dev/null | {
IFS=$'\t' read -ra tags <<< "$(hc tag_status $monitor)"
visible=true
date=""
volume=""
battery=""
wireless=""
windowtitle=""
while true ; do
separator="%{F$accent}|%{F-}"
# draw tags
for i in "${tags[@]}" ; do
case ${i:0:1} in
'#')
echo -n "%{U$accent+u}%{B-}%{F$normal_txt}"
;;
'+')
echo -n "%{B$accent}%{F$normal_bg}"
;;
':')
echo -n "%{B-}%{F$normal_txt}"
;;
'!')
echo -n "%{B$normal_txt}%{F$normal_bg}"
;;
*)
echo -n "%{B-}%{F$inactive_txt}"
;;
esac
echo -n "%{A:herbstclient use ${i:1}:} ${i:1} %{A}%{F-}%{B-}%{U-u}"
done
echo -n "$separator"
echo -n "%{B-}%{F-} ${windowtitle//^/^^}"
#Right part of panel
right="$volume$wireless$battery$date "
echo -n "%{r}$right"
echo
# wait for next event
IFS=$'\t' read -ra cmd || break
case "${cmd[0]}" in
tag*)
#echo "resetting tags" >&2
IFS=$'\t' read -ra tags <<< "$(hc tag_status $monitor)"
;;
volume)
volume="${cmd[@]:1}"
if [ $volume == "off" ] ; then
volume=""
else
volume="$volume $separator%{B-} "
fi
;;
wireless)
wireless="${cmd[@]:1}"
if [ $wireless = "off" ] ; then
wireless=""
else
wireless="$wireless $separator%{B-} "
fi
;;
battery)
battery="${cmd[@]:1}"
if [ $battery == "off" ] ; then
battery=""
else
battery="$battery $separator%{B-} "
fi
;;
date)
#echo "resetting date" >&2
date="${cmd[@]:1}"
;;
focus_changed|window_title_changed)
windowtitle="${cmd[@]:2}"
;;
esac
done
} 2> /dev/null | \
bar -g $panel_width\x$panel_height\+$x+$y -f "$font" \
-u 2 -B "$normal_bg" -F "$normal_txt" | \
while read line; do eval "$line"; done
|