6 STATUS_DIR
=$HOME/var
/run
/status
7 STATUS_FILE__WIFI
=$STATUS_DIR/wifi
8 STATUS_FILE__ENERGY_NOTIFIED_BELLOW_HALF
=$STATUS_DIR/notified_energy_bellow_half
10 load
=$
(awk '{printf("%4.2f", $1)}' /proc
/loadavg
)
12 fan
=$
(awk '/^speed:/ {printf "%4d", $2}' /proc
/acpi
/ibm
/fan
)
14 cpu
=$
($BIN/khatus_cpu_usage_from_proc_since_last_check
)
19 function round(n) {return int(n + 0.5)}
25 prev_file = "/home/siraaj/var/run/status/memory_used_percentage";
26 curr = round(used / total * 100);
27 getline prev < prev_file;
28 print curr > prev_file;
31 } else if (curr < prev) {
36 printf("%s%d%%", direction, curr);
39 temp
=$
(awk 'NR == 1 {print $1 / 1000}' /sys
/class
/thermal
/thermal_zone
0/temp
)
44 bytes_per_sector = 512
45 bytes_per_unit = 1024 * 1024
47 curr_sectors_read = $3
48 curr_sectors_write = $7
50 prev_file_prefix = "/home/siraaj/var/run/status/disk_io"
51 prev_sectors_read_file = prev_file_prefix "_sectors_read"
52 prev_sectors_write_file = prev_file_prefix "_sectors_write"
54 getline prev_sectors_read < prev_sectors_read_file
55 getline prev_sectors_write < prev_sectors_write_file
57 diff_read_sectors = (curr_sectors_read - prev_sectors_read)
58 diff_write_sectors = (curr_sectors_write - prev_sectors_write)
60 diff_read_bytes = diff_read_sectors * bytes_per_sector
61 diff_write_bytes = diff_write_sectors * bytes_per_sector
63 diff_read = diff_read_bytes / bytes_per_unit
64 diff_write = diff_write_bytes / bytes_per_unit
66 print curr_sectors_read > prev_sectors_read_file
67 print curr_sectors_write > prev_sectors_write_file
69 printf("%0.3f▲ %0.3f▼\n", diff_write, diff_read);
72 ' /sys
/block
/dm-
1/stat
77 |
awk -v disk_io
="$disk_io" '
78 function round(n) {return int(n + 0.5)}
80 $1 == "/dev/mapper/kubuntu--vg-root" {
81 curr_perc = $5; sub("%$", "", curr_perc);
82 prev_perc_file = "/home/siraaj/var/run/status/disk_space_used";
83 getline prev_perc < prev_perc_file;
84 print curr_perc > prev_perc_file;
85 if (curr_perc > prev_perc) {
87 } else if (curr_perc < prev_perc) {
92 printf("%s[%d%% %s]", direction, curr_perc, disk_io);
97 |
awk -v wifi_conn
=$
(cat $STATUS_FILE__WIFI) '
99 bytes_per_unit = 1024 * 1024
107 interfaces[sequence] = interface
111 sub("/[0-9]+", "", $2)
113 addrs[interface] = addr
116 /^ +RX: / {transfer_direction = "r"}
117 /^ +TX: / {transfer_direction = "w"}
119 /^ +[0-9]+ +[0-9]+ +[0-9]+ +[0-9]+ +[0-9]+ +[0-9]+ *$/ {
120 io[interface, transfer_direction] = $1;
124 for (i=1; i<=sequence; i++) {
125 interface = interfaces[i]
126 if (addrs[interface]) {
127 curr_read = io[interface, "r"]
128 curr_write = io[interface, "w"]
130 prefix = "/home/siraaj/var/run/status/io_net_" interface
131 prev_read_file = prefix "_read"
132 prev_write_file = prefix "_write"
134 getline prev_read < prev_read_file
135 getline prev_write < prev_write_file
137 diff_read = (curr_read - prev_read ) / bytes_per_unit
138 diff_written = (curr_write - prev_write) / bytes_per_unit
140 print curr_read > prev_read_file
141 print curr_write > prev_write_file
143 io_stat = sprintf("%0.3f▲ %0.3f▼", diff_written, diff_read)
148 label = substr(interface, 1, 1)
149 if (interface == "wlp3s0") {
150 label = label ":" wifi_conn
159 printf("%s:%s%s", label, io_stat, sep)
169 /^ +percentage: +/ {percentage=$2}
170 /^ +state: +/ {state=$2}
172 if (state == "discharging") {
173 direction_of_change = "<"
174 } else if (state == "charging") {
175 direction_of_change = ">"
177 direction_of_change = "="
179 printf("%s%s", direction_of_change, percentage)
182 datetime
=$
(date +'%a, %b %d, %H:%M:%S')
185 # amixer get Master \
190 # sub("^\\[", "", level);
191 # sub("\\]$", "", level);
197 # amixer get Master \
199 # | awk '{print $4}' \
210 for (i=2; i<=NF; i++) printf(" %s", $i);
213 /^[ \t]*Mute:/ {mute = $2}
214 /^[ \t]*front-left:/ {left = $4}
215 /^[ \t]*front-right:/ {right = $4}
220 printf("%s %s", left, right)
226 volume
="[$volume_pactl]"
229 max
=$
(cat /sys
/class
/backlight
/acpi_video
0/max_brightness
)
230 cur
=$
(cat /sys
/class
/backlight
/acpi_video
0/brightness
)
231 awk -v max
=$max -v cur
=$cur 'BEGIN {printf("%d%%", cur/max*100)}'
235 # grep '^status:' /proc/acpi/ibm/bluetooth \
237 # $2 == "disabled" {printf "off"}
238 # $2 == "enabled" {printf "on"}
243 echo -e 'show \n quit' \
248 controllers[++ctrl_count] = controller;
250 /^\t[A-Z][A-Za-z]+:/ {
254 for (i=3; i<=NF; i++) {
256 data[controller, key] = val;
259 # Using the 1st seen controller. Should we select specific instead?
260 power_status = data[controllers[1], "Powered"];
261 if (ctrl_count > 0) {
262 if (power_status == "no") {
264 } else if (power_status == "yes") {
267 printf("Unexpected bluetooth power status: %s\n", power_status)\
269 power_status = "ERROR"
272 power_status = "off" # TODO: Perhaps use differentiated marker?
274 printf("%s", power_status);
279 # xinput list-props 12 \
281 # /^\tDevice Enabled \([0-9]+\):/ {
283 # printf("%s", status);
288 #color_on_bg_gray='\033[m\033[40m'
290 energy_direction
=$
(echo "$energy" | cut
-b 1)
291 energy_percentage
=$
(echo "$energy" |
tr -d '<>=%')
292 if [[ "$energy_direction" = '<' ]]
294 if [[ $energy_percentage -le 5 ]]
296 DISPLAY
=:0.0 notify-send \
298 "Energy CRITICALLY low: $energy" \
299 'CHARGE NOW!!! GO GO GO!!!'
300 elif [[ $energy_percentage -le 10 ]]
302 DISPLAY
=:0.0 notify-send \
304 "Energy VERY low: $energy" \
306 elif [[ $energy_percentage -le 15 ]]
308 DISPLAY
=:0.0 notify-send \
310 "Energy low: $energy" \
312 elif [[ $energy_percentage -le 50 ]]
314 if [[ ! -a "$STATUS_FILE__ENERGY_NOTIFIED_BELLOW_HALF" ]]
316 DISPLAY
=:0.0 notify-send \
318 "Energy bellow half: $energy" \
319 'Where is the charger?'
320 touch "$STATUS_FILE__ENERGY_NOTIFIED_BELLOW_HALF"
324 rm -f "$STATUS_FILE__ENERGY_NOTIFIED_BELLOW_HALF"
327 weather
=$
(awk 'NR == 1 {printf("%d°F", $1)}' ~
/var
/run
/metar-KJFK-decoded-temp-fahrenheit
)
329 signal_last_msg_age
=$
(
330 ls -lt --time-style=+%s
$HOME/var
/lib
/signal
/latest_message.json \
331 |
awk -v now_seconds
=$
(date +%s
) \
334 seconds = now_seconds - mtime_seconds;
335 minutes = seconds / 60;
336 hours = minutes / 60;
342 printf(fmt " s\n", seconds);
343 printf(fmt " m\n", minutes);
344 printf(fmt " h\n", hours);
345 printf(fmt " d\n", days);
346 printf(fmt " w\n", weeks);
347 printf(fmt " mo\n", months);
357 | nc
127.0.0.1 6600 \
364 state = status["state:"]
366 if (state == "play") {
368 } else if (state == "pause") {
370 } else if (state == "stop") {
380 | nc
127.0.0.1 6600 \
381 |
awk -v max_chars
=10 '
389 for (i=3; i<=NF; i++) {val = val " " $i}
396 } else if (data["Title:"]) {
400 last = split(file, parts, "/")
403 printf("%s", substr(out, 1, max_chars))
410 --format=csv
,noheader
,nounits \
411 --query-gpu=memory.total
,memory.used
,temperature.gpu \
417 mem_used_percent = (100 * mem_used) / mem_total;
418 printf("[%d%% %dC]", mem_used_percent, temp);
431 C=[$cpu ${temp}°C ${fan}rpm]\
441 S=$screen_brightness\
445 [$mpd_state $mpd_current]\
447 $signal_last_msg_age\