-
Notifications
You must be signed in to change notification settings - Fork 3
/
brm_bar
executable file
·207 lines (165 loc) · 4.46 KB
/
brm_bar
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
#!/bin/bash
if [[ $(pgrep -cx brm_bar) > 1 ]]; then
exit 1;
fi
# Constants
dir=$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )
support_dir="$dir/brm_bar_support"
icon_dir="$support_dir/icons"
fifo=/tmp/brm_bar_fifo
font="Source Code Pro:pixelsize=12:antialias=true:hinting=true"
background="#626262" #$dir/../bar/test.png" #"#626262"
width=1440
# Globals
stat=""
desktops=""
battery=""
wifi=""
volume=""
song=""
date=""
uptime=""
function get_desktops() {
desktops_raw="$1"
desktops=""
IFS=':' read -a desktop_array <<< "$desktops_raw"
index=0
for element in "${desktop_array[@]}"
do
if [[ $element == "O"* ]] || [[ $element == "F"* ]]; then
desktops="${desktops} %{I:$icon_dir/desktop_2.png:}"
else if [[ $element == "o"* ]]; then
desktops="${desktops} %{A:bspc desktop -f ^$index:}%{I:$icon_dir/desktop_1.png:}%{A}"
else if [[ $element == "f"* ]]; then
desktops="${desktops} %{A:bspc desktop -f ^$index:}%{I:$icon_dir/desktop_0.png:}%{A}"
fi
fi
fi
(( index += 1 ))
done
}
function get_volume() {
volume_raw="$1"
volume_percent=$(sed 's/.*\[\(.*\)%\].*/\1/g' <<< $volume_raw)
if [[ $volume_raw == *"[off]"* ]]; then
volume="%{I:$icon_dir/volume_mute.png:}\t"
else
volume_strength=$(( (volume_percent - 1) / 25 ))
volume="%{I:$icon_dir/volume_$volume_strength.png:}\t"
fi
}
function do_update() {
date=$(date +%c)
if [[ $(pgrep -c pianobar) < 1 ]]; then
song=""
fi
}
function do_slow_update() {
battery_raw=$(acpi)
battery_parsed=$(sed 's/.\+, \(.\+\)%.*/\1/g' <<< $battery_raw)
if [[ $battery_raw == *"Charging"* ]]; then
battery="$battery_parsed%% %{I:$icon_dir/battery_charging.png:}\t\t"
else
percent=$(( 7 * ($battery_parsed + 5) / 100 ))
battery="$battery_parsed%% %{I:$icon_dir/battery_$percent.png:}\t\t"
fi
wifi_line=$(iwconfig 2> /dev/null |grep "Link Quality")
wifi_strength=0
if [[ $wifi_line != "" ]]; then
wifi_strength=$(iwconfig 2>/dev/null | grep "Link Quality" | sed 's/.*Link Quality=\(.*\) Signal.*/\1/g' | sed '/[0-9]\+\/[0-9]\+/!s/.*/-1/g')
fi
if [[ $wifi_strength == "" ]]; then
wifi_strength=0
fi
if [[ $wifi_strength == "-1" ]]; then
wifi_percent="x"
else
wifi_percent=$(( 4 * (105*$wifi_strength) / 100 ))
fi
wifi="%{I:$icon_dir/wifi_$wifi_percent.png:}\t\t"
uptime=$(uptime -p | tr -d '\n' | sed 's/up //g')
}
function get_song() {
song="\t$1"
}
function parse_fifo() {
if [[ {"$1" == "[STATUS]"* ]]; then
stat="${1:8}"
fi
if [[ "$1" == "[DESKTOP]"* ]]; then
get_desktops "${1:9}"
fi
if [[ "$1" == "[VOLUME]"* ]]; then
get_volume "${1:8}"
fi
if [[ "$1" == "[SONG]"* ]]; then
get_song "${1:6}"
fi
if [[ "$1" == "[UPDATE]" ]]; then
do_update
fi
if [[ "$1" == "[UPDATESLOW]" ]]; then
do_slow_update
fi
}
# Spawn new helper programs.
killall brm_bar_ping -q
$support_dir/brm_bar_ping &
killall brm_bar_ping_slow -q
sleep .1 && $support_dir/brm_bar_ping_slow &
killall brm_bar_bspc -q
sleep .2 && $support_dir/brm_bar_bspc &
# Make sure the fifo is real!
if [ ! -p $fifo ]; then
mkfifo $fifo;
fi
# Initial calls
sleep .1 && echo "[VOLUME]$(amixer get Master|grep dB)" > $fifo &
while read line < $fifo; do
parse_fifo "$line"
output=""
# Center
output="$output %{c}"
# Apps
#output="$output [ "
pianobar="%{A:pianobar &:}%{I:$icon_dir/pandora.png:}%{A}"
output="$output $pianobar"
gimp="%{A:gimp &:}%{I:$icon_dir/gimp.png:}%{A}"
output="$output $gimp"
firefox="%{A:firefox &:}%{I:$icon_dir/firefox.png:}%{A}"
output="$output $firefox"
terminal="%{A:urxvt &:}%{I:$icon_dir/terminal.png:}%{A}"
output="$output $terminal"
#output="$output ]"
# Right side
output="$output %{r}"
if [ "$volume" != "" ]; then
output="${output} $volume"
fi
if [ "$battery" != "" ]; then
output="${output} $battery"
fi
if [ "$wifi" != "" ]; then
output="${output} $wifi"
fi
if [ "$date" != "" ]; then
output="${output} $date \t"
fi
# Left side
output="$output %{l}"
if [ "$desktops" != "" ]; then
output="${output} \t $desktops"
fi
if [ "$song" != "" ]; then
output="${output} $song"
fi
# if [ "$uptime" != "" ]; then
# output="${output} \t $uptime"
# fi
if [ "$stat" != "" ]; then
output="${output} $stat"
fi
echo -e $output | sed 's/\t/ /g';
done | bar -g${width}x20+0+0 -B $background -f $font | sh &> /tmp/brm_bar_log
# cpu=$(top -b -n1 |grep "Cpu"|awk '{printf "%0.2f ", $3}')
# output="$output \t CPU: $cpu"