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 DISK_SPACE_DEVICE
='/dev/mapper/kubuntu--vg-root'
11 SCREEN_BRIGHTNESS_DEVICE_NAME
='acpi_video0'
12 SCREEN_BRIGHTNESS_DEVICE_PATH
="/sys/class/backlight/$SCREEN_BRIGHTNESS_DEVICE_NAME"
15 load
=$
(awk '{printf("%4.2f", $1)}' /proc
/loadavg
)
17 fan
=$
(awk '/^speed:/ {printf "%4d", $2}' /proc
/acpi
/ibm
/fan
)
19 #cpu=$($BIN/khatus_cpu_usage_from_proc_since_last_check)
24 function round(n) {return int(n + 0.5)}
30 prev_file = ENVIRON["HOME"] "/var/run/status/memory_used_percentage";
31 curr = round(used / total * 100);
32 getline prev < prev_file;
33 print curr > prev_file;
36 } else if (curr < prev) {
41 printf("%s%d%%", direction, curr);
44 temp
=$
(awk 'NR == 1 {print $1 / 1000}' /sys
/class
/thermal
/thermal_zone
0/temp
)
49 bytes_per_sector = 512
50 bytes_per_unit = 1024 * 1024
52 curr_sectors_read = $3
53 curr_sectors_write = $7
55 prev_file_prefix = ENVIRON["HOME"] "/var/run/status/disk_io"
56 prev_sectors_read_file = prev_file_prefix "_sectors_read"
57 prev_sectors_write_file = prev_file_prefix "_sectors_write"
59 getline prev_sectors_read < prev_sectors_read_file
60 getline prev_sectors_write < prev_sectors_write_file
62 diff_read_sectors = (curr_sectors_read - prev_sectors_read)
63 diff_write_sectors = (curr_sectors_write - prev_sectors_write)
65 diff_read_bytes = diff_read_sectors * bytes_per_sector
66 diff_write_bytes = diff_write_sectors * bytes_per_sector
68 diff_read = diff_read_bytes / bytes_per_unit
69 diff_write = diff_write_bytes / bytes_per_unit
71 print curr_sectors_read > prev_sectors_read_file
72 print curr_sectors_write > prev_sectors_write_file
74 printf("%0.3f▲ %0.3f▼\n", diff_write, diff_read);
77 ' "/sys/block/$DISK_IO_DEVICE/stat"
83 -v disk_io
="$disk_io" \
84 -v device
="$DISK_SPACE_DEVICE" \
86 function round(n) {return int(n + 0.5)}
89 curr_perc = $5; sub("%$", "", curr_perc);
90 prev_perc_file = ENVIRON["HOME"] "/var/run/status/disk_space_used";
91 getline prev_perc < prev_perc_file;
92 print curr_perc > prev_perc_file;
93 if (curr_perc > prev_perc) {
95 } else if (curr_perc < prev_perc) {
100 printf("%s[%d%% %s]", direction, curr_perc, disk_io);
103 # TODO: Wi-Fi status file should be a file per-wifi-device
107 -v wifi_conn
="$(cat $STATUS_FILE__WIFI)" \
108 -v prefixes_of_interfaces_to_show
='w' \
111 bytes_per_unit = 1024 * 1024
119 interfaces[sequence] = interface
123 sub("/[0-9]+", "", $2)
125 addrs[interface] = addr
128 /^ +RX: / {transfer_direction = "r"}
129 /^ +TX: / {transfer_direction = "w"}
131 /^ +[0-9]+ +[0-9]+ +[0-9]+ +[0-9]+ +[0-9]+ +[0-9]+ *$/ {
132 io[interface, transfer_direction] = $1;
136 for (seq=1; seq<=sequence; seq++) {
137 interface = interfaces[seq]
138 label = substr(interface, 1, 1)
139 if (addrs[interface]) {
140 curr_read = io[interface, "r"]
141 curr_write = io[interface, "w"]
143 prefix = ENVIRON["HOME"] "/var/run/status/io_net_" interface
144 prev_read_file = prefix "_read"
145 prev_write_file = prefix "_write"
147 getline prev_read < prev_read_file
148 getline prev_write < prev_write_file
150 diff_read = (curr_read - prev_read ) / bytes_per_unit
151 diff_written = (curr_write - prev_write) / bytes_per_unit
153 print curr_read > prev_read_file
154 print curr_write > prev_write_file
156 io_stat = sprintf("%0.3f▲ %0.3f▼", diff_written, diff_read)
157 if (interface ~ "^w") {
158 label = label ":" wifi_conn
163 number_of_interfaces_to_show = \
165 prefixes_of_interfaces_to_show,\
166 array_of_prefixes_of_interfaces_to_show,\
169 for (n = 1; n <= number_of_interfaces_to_show; n++) {
170 prefix = array_of_prefixes_of_interfaces_to_show[n]
171 if (interface ~ ("^" prefix)) {
172 if (++count_printed > 1) {
177 printf("%s%s:%s", sep, label, io_stat)
189 /^ +percentage: +/ {percentage=$2}
190 /^ +state: +/ {state=$2}
192 if (state == "discharging") {
193 direction_of_change = "<"
194 } else if (state == "charging") {
195 direction_of_change = ">"
197 direction_of_change = "="
199 printf("%s%s", direction_of_change, percentage)
202 datetime
=$
(date +'%a %b %d %H:%M:%S')
204 # date +'%a %u %b %d %H:%M:%S' \
214 # for (i=1; i<=7; i++) {
215 # if (i == 6 || i == 4) {
221 # if (i == wday_seq) {
222 # #symbol = substr(wday_name, 1, 1)
224 # } else if (i < wday_seq){
229 # week = week sep symbol
232 # print "["week"]", month, mday, time;
238 # amixer get Master \
243 # sub("^\\[", "", level);
244 # sub("\\]$", "", level);
250 # amixer get Master \
252 # | awk '{print $4}' \
263 for (i=2; i<=NF; i++) printf(" %s", $i);
266 /^[ \t]*Mute:/ {mute = $2}
267 /^[ \t]*front-left:/ {left = $4}
268 /^[ \t]*front-right:/ {right = $4}
273 printf("%s %s", left, right)
279 volume
="($volume_pactl)"
283 $
(cat $SCREEN_BRIGHTNESS_DEVICE_PATH/brightness
)
284 / $
(cat $SCREEN_BRIGHTNESS_DEVICE_PATH/max_brightness
)
290 # grep '^status:' /proc/acpi/ibm/bluetooth \
292 # $2 == "disabled" {printf "off"}
293 # $2 == "enabled" {printf "on"}
298 echo -e 'show \n quit' \
303 controllers[++ctrl_count] = controller;
305 /^\t[A-Z][A-Za-z]+:/ {
309 for (i=3; i<=NF; i++) {
311 data[controller, key] = val;
314 # Using the 1st seen controller. Should we select specific instead?
315 power_status = data[controllers[1], "Powered"];
316 if (ctrl_count > 0) {
317 if (power_status == "no") {
319 } else if (power_status == "yes") {
322 printf("Unexpected bluetooth power status: %s\n", power_status)\
324 power_status = "ERROR"
327 power_status = "off" # TODO: Perhaps use differentiated marker?
329 printf("%s", power_status);
334 # xinput list-props 12 \
336 # /^\tDevice Enabled \([0-9]+\):/ {
338 # printf("%s", status);
343 #color_on_bg_gray='\033[m\033[40m'
345 energy_direction
=$
(echo "$energy" | cut
-b 1)
346 energy_percentage
=$
(echo "$energy" |
tr -d '<>=%')
347 if [[ "$energy_direction" = '<' ]]
349 if [[ $energy_percentage -le 5 ]]
351 DISPLAY
=:0.0 notify-send \
353 "Energy CRITICALLY low: $energy" \
354 'CHARGE NOW!!! GO GO GO!!!'
355 elif [[ $energy_percentage -le 10 ]]
357 DISPLAY
=:0.0 notify-send \
359 "Energy VERY low: $energy" \
361 elif [[ $energy_percentage -le 15 ]]
363 DISPLAY
=:0.0 notify-send \
365 "Energy low: $energy" \
367 elif [[ $energy_percentage -le 50 ]]
369 if [[ ! -a "$STATUS_FILE__ENERGY_NOTIFIED_BELLOW_HALF" ]]
371 DISPLAY
=:0.0 notify-send \
373 "Energy bellow half: $energy" \
374 'Where is the charger?'
375 touch "$STATUS_FILE__ENERGY_NOTIFIED_BELLOW_HALF"
379 rm -f "$STATUS_FILE__ENERGY_NOTIFIED_BELLOW_HALF"
382 weather
=$
(awk 'NR == 1 {printf("%s°F", $1)}' ~
/var
/run
/metar-KJFK-decoded-temp-fahrenheit
)
384 #signal_last_msg_age=$(
385 # ls -lt --time-style=+%s $HOME/var/lib/signal/latest_message.json \
386 # | awk -v now_seconds=$(date +%s) \
388 # mtime_seconds = $6;
389 # seconds = now_seconds - mtime_seconds;
390 # minutes = seconds / 60;
391 # hours = minutes / 60;
394 # months = days / 30;
397 # printf(fmt " s\n", seconds);
398 # printf(fmt " m\n", minutes);
399 # printf(fmt " h\n", hours);
400 # printf(fmt " d\n", days);
401 # printf(fmt " w\n", weeks);
402 # printf(fmt " mo\n", months);
412 | nc
127.0.0.1 6600 \
413 |
awk -v max_chars
=10 '
421 for (i=3; i<=NF; i++) {val = val " " $i}
427 title = data["Title:"]
435 last = split(file, parts, "/")
441 printf("%s", substr(out, 1, max_chars))
448 | nc
127.0.0.1 6600 \
450 -v current_song
="$mpd_currentsong" \
456 /^time: +[0-9]+:[0-9]+$/ {
458 seconds_current = time[1]
459 seconds_total = time[2]
461 hours = int(seconds_current / 60 / 60);
462 secs_beyond_hours = seconds_current - (hours * 60 * 60);
463 mins = int(secs_beyond_hours / 60);
464 secs = secs_beyond_hours - (mins * 60);
466 current_time = sprintf("%d:%.2d:%.2d", hours, mins, secs)
468 current_time = sprintf("%.2d:%.2d", mins, secs)
471 if (seconds_total > 0) {
472 time_percentage = (seconds_current / seconds_total) * 100
473 current_percentage = sprintf("%d%%", time_percentage)
475 current_percentage = "~"
479 function print_known_state(symbol) {
482 symbol, current_time, current_percentage, current_song \
486 function print_unknown_state(symbol) {
491 state = status["state:"]
493 if (state == "play") {
494 print_known_state("▶")
495 } else if (state == "pause") {
496 print_known_state("❚❚")
497 } else if (state == "stop") {
498 print_known_state("⬛")
500 print_unknown_state("--")
508 #--format=csv,noheader,nounits \
509 #--query-gpu=memory.total,memory.used,temperature.gpu \
515 #mem_used_percent = (100 * mem_used) / mem_total;
516 #printf("[%d%% %dC]", mem_used_percent, temp);
527 C=[$load ${temp}°C ${fan}rpm]\
535 *$screen_brightness%\