-
-
Notifications
You must be signed in to change notification settings - Fork 75
/
status
executable file
·80 lines (67 loc) · 1.7 KB
/
status
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
#!/usr/bin/env bash
# Initialize
printf "$$" > ~/.cache/pidofbar
sec=0
# Update functions
update_cpu() {
cpu=$(awk '{print $1}' /proc/loadavg)
}
update_memory() {
memory=$(free -h | awk 'NR==2 {print $3}')
}
update_time() {
time=$(date "+%b %d %H:%M ")
}
update_weather() {
weather=$(curl -s "wttr.in/dallas?format=1" | cut -c1)
}
update_bat() {
if [[ -e /sys/class/power_supply/BAT0/status ]]; then
bat_status=$(< /sys/class/power_supply/BAT0/status)
if [[ -e /sys/class/power_supply/BAT0/capacity ]]; then
bat_capacity=$(< /sys/class/power_supply/BAT0/capacity)
bat="$bat_status $bat_capacity%"
else
bat="$bat_status (capacity not available)"
fi
fi
}
update_vol() {
vol="奄 $(pactl list sinks | awk '/Volume:/ {print $5}' | head -n 1 | tr -d '%')%"
}
update_backlight() {
if [[ -e /sys/class/backlight/intel_backlight/actual_brightness ]]; then
actual_brightness=$(< /sys/class/backlight/intel_backlight/actual_brightness)
max_brightness=$(< /sys/class/backlight/intel_backlight/max_brightness)
backlight="☀$((actual_brightness * 100 / max_brightness))%"
fi
}
# Display function
display() {
status=""
[[ -n "$bat" ]] && status+="$bat "
[[ -n "$backlight" ]] && status+="$backlight "
[[ -n "$vol" ]] && status+="$vol "
[[ -n "$time" ]] && status+="$time"
xsetroot -name "$status"
}
# Set up signal handlers
trap "update_vol; display" "RTMIN"
trap "update_backlight; display" "RTMIN+1"
trap "update_bat; display" "RTMIN+2"
# Initial updates
update_vol
update_backlight
# Main loop
while true; do
sleep 1
sec=$((sec + 1))
case $((sec % 60)) in
0) update_bat;;
[1-5])
update_time
update_vol
display
;;
esac
done