-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathbar.sh
More file actions
executable file
·192 lines (173 loc) · 6.21 KB
/
bar.sh
File metadata and controls
executable file
·192 lines (173 loc) · 6.21 KB
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
#!/bin/bash
# ^-- POSIX shell doesn't have trap RTMIN so we use bash
sec=0
proc_num=$(nproc)
space=" " # ` `(U+2009) is the Thin Space
update_time () {
icon=""
case "$(date +'%I')" in
01) icon="" ;;
02) icon="" ;;
03) icon="" ;;
04) icon="" ;;
05) icon="" ;;
06) icon="" ;;
07) icon="" ;;
08) icon="" ;;
09) icon="" ;;
10) icon="" ;;
11) icon="" ;;
12) icon="" ;;
esac
time="$icon $(date '+%H:%M')"
}
update_bluetooth() {
icon="^#0000ffFF^#!"
if ! pgrep -x 'bluetoothd' >/dev/null; then
icon=""
else
level="$(bluetoothctl info | grep -m1 'Battery Percentage' | awk -F'[()]' '{print $2}')"
[ -n "$level" ] && icon="" level="${level}%"
fi
bluetooth="${icon}${level}"
}
update_volume() {
text=$(amixer get Master | tail -1)
status=$(echo "$text" | grep -oE '\[on\]|\[off\]')
level=$(echo "$text" | grep -oE '[0-9]+%')
[ "$status" = "[on]" ] && icon=" " || icon="^#ff0000FF^#!"
volume="${icon}${level}"
}
update_microphone() {
text=$(amixer get Capture | tail -1)
status=$(echo "$text" | grep -oE '\[on\]|\[off\]')
level=$(echo "$text" | grep -oE '[0-9]+%')
[ "$status" = "[on]" ] && icon="" || icon="^#ff0000FF^#!"
microphone="${icon}" #${level}"
}
update_battery () {
icon=""
POWER="/sys/class/power_supply"
if [ -e "$POWER/qcom-battmgr-bat" ]; then
status="$(cat $POWER/qcom-battmgr-bat/status)"
level="$(cat $POWER/qcom-battmgr-bat/capacity)"
else
status="$(cat $POWER/BAT?/status)"
level="$(cat $POWER/BAT?/capacity)"
fi
case "$status" in
"Discharging")
case "$level" in
[0-5]) icon="^#ff0000FF^#!";;
[6-9]) icon="^#ff0000FF^#!";;
1[0-9]) icon="^#ff9c00FF^#!";;
2[0-9]) icon="";;
3[0-9]) icon="";;
4[0-9]) icon="";;
5[0-9]) icon="";;
6[0-9]) icon="";;
7[0-9]) icon="";;
8[0-9]) icon="";;
9[0-9]) icon="";;
100) icon="^#00ff00FF^#!";;
esac
level="${level}%"
;;
"Not charging")
icon="" level="${level}%"
;;
"Charging")
icon="" level="${level}%"
;;
esac
if [ "$level" != "" ]; then
battery="${icon}${level}"
else
battery=""
fi
}
update_ethernet() {
status="$(cat /sys/class/net/e*/operstate 2>/dev/null)"
icon=" "
[ "$status" != "up" ] && icon=" "
ethernet="$icon"
}
update_wifi() {
status="$(cat /sys/class/net/wlan*/operstate 2>/dev/null)"
level="$(awk '/^\s*w/ {print int($3 * 100 / 70)"%"}' /proc/net/wireless)"
[ "$status" = "up" ] && icon=" " || icon="^#ff0000FF ^#!" level=""
wifi="${icon}${level}"
}
update_temperature() {
icon=""
THERMEL="/sys/class/thermal/thermal_zone0/temp"
value="$(sed 's/000$//' "$THERMEL")"
[ -z "$value" ] && icon="" temperature=""
case "$value" in
[0-3][0-9]) icon="" ;;
4[0-9]) icon="" ;;
[5-6][0-9]) icon="" ;;
[7-9][0-9]) icon="" ;;
esac
[ -z "$value" ] || value="${value}℃"
temperature="${icon}${value}"
}
update_cpu() {
usage="$(( $(awk '{ printf "%.0f", $1*100 }' /proc/loadavg) / $proc_num ))"
[ -z "$usage" ] || usage="${usage}%"
cpu=" ${usage}"
}
update_memory() {
memory=" $(free | awk 'NR==2 {printf "%.0f%%(%.1fG)\n", $3/$2 * 100, $3/1024/1024}')"
}
update_keyboard() {
if [ -e "$XDG_RUNTIME_DIR/rivermap.state" ]; then
keyboard=" $(cat "$XDG_RUNTIME_DIR/rivermap.state" | sed 's/ (Proycon)//g' | sed 's/Universal //g')"
else
keyboard="^#ff0000FF^#!"
fi
}
update_task() {
task=$(todo.sh timetrack current -d | sed 's/&/&/g' | awk '{print substr($0, 0, 40)}')
}
update_volume;update_time
update_microphone;
trap "update_volume;display" "RTMIN" # -34 .local/bin/audio
trap "update_microphone;display" "RTMIN+1" # -35 .local/bin/audio
trap "update_brightness;display" "RTMIN+2" # -36 .local/bin/bright
trap "update_keyboard;display" "RTMIN+3" # -37
trap "update_task;display" "RTMIN+4" # -38
display () {
#printf "%s" "${delimiter_home}${memory}${space}${cpu}${space}${temperature}${separator}${wifi}${space}${ethernet}${separator}${brightness}${space}${microphone}${space}${volume}${separator}${battery}${space}${bluetooth}${separator}${time}${delimiter_end}"
printf "%s\n" "(${task}...)${space}${keyboard}${space}${cpu}${space}${wifi}${space}${microphone}${volume}${space}${battery}${space}${time}"
printf "%s\n" "${keyboard}${space}${cpu}${space}${wifi}${space}${microphone}${volume}${space}${battery}${space}${time}" > "$XDG_RUNTIME_DIR/bar.out"
}
MAINPID=$$
~/dotfiles/scripts/bar_rivermap.sh $MAINPID 2> "$XDG_RUNTIME_DIR/rivermap.log" &
~/dotfiles/scripts/bar_timetrack.sh $MAINPID 2> "$XDG_RUNTIME_DIR/timetrack.log" &
while true
do
# to update item ever n seconds with a offset of m
{
## [ $((sec % n)) -eq m ] && udpate_item
[ $((sec % 60 )) -eq 0 ] && update_task # update task every 10 seconds
[ $((sec % 60 )) -eq 0 ] && update_keyboard # update task every 10 seconds
[ $((sec % 60 )) -eq 0 ] && update_volume # update volume every minute
[ $((sec % 60 )) -eq 0 ] && update_microphone # update volume every minute
[ $((sec % 10 )) -eq 0 ] && update_time # update time every 10 seconds
if [ "$HOSTNAME" != "pollux" ]; then
[ $((sec % 10)) -eq 0 ] && update_wifi
[ $((sec % 10)) -eq 0 ] && update_battery
#[ $((sec % 10)) -eq 0 ] && update_bluetooth
[ $((sec % 10)) -eq 0 ] && update_ethernet
fi
#[ $((sec % 5)) -eq 0 ] && update_temperature
[ $((sec % 5)) -eq 0 ] && update_cpu
#[ $((sec % 5)) -eq 0 ] && update_memory
# how often the display updates ( 5 seconds )
[ $((sec % 5 )) -eq 0 ] && display
sec=$((sec + 1))
}
sleep 1 &
wait $!
done