-
Notifications
You must be signed in to change notification settings - Fork 0
/
baraction
executable file
·86 lines (73 loc) · 2.01 KB
/
baraction
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
#!/bin/sh
cpu() {
icon=
read -r cpu a b c previdle rest </proc/stat
total=$((a + b + c + previdle))
prev_stat_file="/tmp/prev_cpu_stat"
if [ -f "$prev_stat_file" ]; then
read -r _ a_prev b_prev c_prev previdle_prev _ <"$prev_stat_file"
cpu_usage=$((100 * ((total - (a_prev + b_prev + c_prev + previdle_prev)) - (previdle - previdle_prev)) / (total - (a_prev + b_prev + c_prev + previdle_prev))))
printf "%s%3d%%" "$icon" "$cpu_usage"
else
printf "N/A"
fi
echo "$cpu $a $b $c $previdle $rest" >"$prev_stat_file"
}
ram() {
icon=
free_output=$(free)
used=$(echo "$free_output" | awk '/Mem:/ {print $3}')
total=$(echo "$free_output" | awk '/Mem:/ {print $2}')
percent=$((200 * used / total % 2 == 0 ? 100 * used / total : 101 * used / total))
printf "%s%3d%%" "$icon" "$percent"
}
ssd() {
icon=
SSD=$(df -P /home | awk 'NR==2 {print int($5)}')
printf "%s%3d%%" "$icon" "$SSD"
}
bat() {
read -r charging </sys/class/power_supply/AC/online
read -r percent </sys/class/power_supply/BAT0/capacity
icon=$(case "$percent" in
[1-9]) echo "" ;;
[1-3][0-9]) echo "" ;;
[4-5][0-9]) echo "" ;;
[6-7][0-9]) echo "" ;;
*) echo "" ;;
esac)
[ "$charging" = "1" ] && icon="⚡"
printf "%s%3d%%" "$icon" "$percent"
}
vol() {
volume=$(pactl get-sink-volume @DEFAULT_SINK@ | grep -o '[0-9]*%' | head -1 | tr -d '%')
mute=$(pactl get-sink-mute @DEFAULT_SINK@ | grep -o 'yes')
if [ "$mute" = "yes" ]; then
icon=""
else
icon=""
fi
printf "%s%3d%%" "$icon" "$volume"
}
mic() {
if find /proc/asound/card*/input*/status -type f -exec grep -q "RUNNING" {} + 2>/dev/null; then
printf ""
else
printf ""
fi
}
net() {
if ip a | grep 'wlan0' | grep -c 'UP' >/dev/null; then
printf ""
else
printf ""
fi
}
blu() {
find /sys/class/bluetooth -name powered -quit 2>/dev/null && printf "" || printf ""
}
SLEEP_SEC=2
while :; do
echo "$(cpu) $(ram) $(ssd) $(bat) $(mic) $(blu) $(net) "
sleep $SLEEP_SEC
done