-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdwmstatus
executable file
·106 lines (82 loc) · 2.73 KB
/
dwmstatus
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
#!/bin/bash
#
# file: dwmstatus
# author: Brian Buccola <[email protected]>
#
# description: Functions for printing system info into dwm's status bar via
# xsetroot.
bat() {
bat_status=$(</sys/class/power_supply/BAT0/status)
bat_pct=$(</sys/class/power_supply/BAT0/capacity)
bat_time_left=$(acpi -b | head -n1 | awk '{ print $5 }' | cut -d: -f1,2)
echo -n "$bat_pct%"
[[ "$bat_status" = "Discharging" ]] && echo -n " ($bat_time_left)"
[[ "$bat_status" = "Charging" ]] && echo -n " (charging)"
[[ "$bat_status" = "Unknown" ]] && echo -n " (idle)"
}
ban() {
interface=$(iwconfig 2>&1 | awk '/^w/ { print $1 }')
rx1=$(</sys/class/net/"$interface"/statistics/rx_bytes)
tx1=$(</sys/class/net/"$interface"/statistics/tx_bytes)
sleep 1
rx2=$(</sys/class/net/"$interface"/statistics/rx_bytes)
tx2=$(</sys/class/net/"$interface"/statistics/tx_bytes)
rx_rate=$(( $rx2 - $rx1 ))
tx_rate=$(( $tx2 - $tx1 ))
# shift by 10 bytes to get KiB/s.
rx_kib=$(( $rx_rate >> 10 ))
tx_kib=$(( $tx_rate >> 10 ))
# incoming
echo -n "down: "
if [[ "$rx_rate" -gt 1048576 ]]; then
printf '%sM' $(echo "scale=1; $rx_kib / 1024" | bc)
else
echo -n "${rx_kib}K"
fi
echo -n " "
# outgoing
echo -n "up: "
if [[ "$tx_rate" -gt 1048576 ]]; then
printf '%sM' $(echo "scale=1; $tx_kib / 1024" | bc)
else
echo -n "${tx_kib}K"
fi
}
dat() {
date '+%a %d %b %H:%M'
}
mem() {
mem=$(awk '/^Mem/ { print $3 }' <(free -h))
echo -n "$mem"
}
mpd() {
mpd=$(mpc current -f '[%artist% - ]%title%')
[[ -n "$mpd" ]] && echo -n "$mpd" || exit 1
}
ups() {
ups_official=$(</tmp/checkup-official)
ups_aur=$(</tmp/checkup-aur)
echo -n "$ups_official($ups_aur)"
}
vol() {
vol_status=$(amixer get Master | tail -n1 | sed -r 's/.*\[(on|off)\].*/\1/')
vol_pct=$(amixer get Master | tail -n1 | sed -r 's/.*\[(.*)%\].*/\1/')
[[ "$vol_status" = "off" ]] && echo -n "mute"
[[ "$vol_status" = "on" ]] && echo -n "$vol_pct%"
}
wea() {
weather=$(</tmp/weather)
echo -n "$weather"
}
wif() {
interface=$(iwconfig 2>&1 | awk '/^w/ { print $1 }')
wifi_essid=$(iwconfig "$interface" | awk -F '"' '/ESSID/ { print $2 }')
wifi_status=$(</sys/class/net/"$interface"/operstate)
wifi_quality=$(grep "$interface" /proc/net/wireless | awk '{ print int($3 * 100 / 70) }')
[[ "$wifi_status" = "up" ]] && echo -n "$wifi_essid $wifi_quality%" || exit 1
}
if [[ "$(wif)" ]]; then
xsetroot -name "$(mpd && echo -n ' · ')$(wif) · $(ban) · $(ups) · bat: $(bat) · vol: $(vol) · $(wea) · $(dat)"
else
xsetroot -name "$(mpd && echo -n ' · ')bat: $(bat) · vol: $(vol) · $(dat)"
fi