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'
13 load
=$
(awk '{printf("%4.2f", $1)}' /proc
/loadavg
)
15 fan
=$
(awk '/^speed:/ {printf "%4d", $2}' /proc
/acpi
/ibm
/fan
)
17 #cpu=$($BIN/khatus_cpu_usage_from_proc_since_last_check)
22 function round(n) {return int(n + 0.5)}
28 prev_file = ENVIRON["HOME"] "/var/run/status/memory_used_percentage";
29 curr = round(used / total * 100);
30 getline prev < prev_file;
31 print curr > prev_file;
34 } else if (curr < prev) {
39 printf("%s%d%%", direction, curr);
42 temp
=$
(awk 'NR == 1 {print $1 / 1000}' /sys
/class
/thermal
/thermal_zone
0/temp
)
47 bytes_per_sector = 512
48 bytes_per_unit = 1024 * 1024
50 curr_sectors_read = $3
51 curr_sectors_write = $7
53 prev_file_prefix = ENVIRON["HOME"] "/var/run/status/disk_io"
54 prev_sectors_read_file = prev_file_prefix "_sectors_read"
55 prev_sectors_write_file = prev_file_prefix "_sectors_write"
57 getline prev_sectors_read < prev_sectors_read_file
58 getline prev_sectors_write < prev_sectors_write_file
60 diff_read_sectors = (curr_sectors_read - prev_sectors_read)
61 diff_write_sectors = (curr_sectors_write - prev_sectors_write)
63 diff_read_bytes = diff_read_sectors * bytes_per_sector
64 diff_write_bytes = diff_write_sectors * bytes_per_sector
66 diff_read = diff_read_bytes / bytes_per_unit
67 diff_write = diff_write_bytes / bytes_per_unit
69 print curr_sectors_read > prev_sectors_read_file
70 print curr_sectors_write > prev_sectors_write_file
72 printf("%0.3f▲ %0.3f▼\n", diff_write, diff_read);
75 ' "/sys/block/$DISK_IO_DEVICE/stat"
81 -v disk_io
="$disk_io" \
82 -v device
="$DISK_SPACE_DEVICE" \
84 function round(n) {return int(n + 0.5)}
87 curr_perc = $5; sub("%$", "", curr_perc);
88 prev_perc_file = ENVIRON["HOME"] "/var/run/status/disk_space_used";
89 getline prev_perc < prev_perc_file;
90 print curr_perc > prev_perc_file;
91 if (curr_perc > prev_perc) {
93 } else if (curr_perc < prev_perc) {
98 printf("%s[%d%% %s]", direction, curr_perc, disk_io);
101 # TODO: Wi-Fi status file should be a file per-wifi-device
105 -v wifi_conn
="$(cat $STATUS_FILE__WIFI)" \
106 -v prefixes_of_interfaces_to_show
='w' \
109 bytes_per_unit = 1024 * 1024
117 interfaces[sequence] = interface
121 sub("/[0-9]+", "", $2)
123 addrs[interface] = addr
126 /^ +RX: / {transfer_direction = "r"}
127 /^ +TX: / {transfer_direction = "w"}
129 /^ +[0-9]+ +[0-9]+ +[0-9]+ +[0-9]+ +[0-9]+ +[0-9]+ *$/ {
130 io[interface, transfer_direction] = $1;
134 for (seq=1; seq<=sequence; seq++) {
135 interface = interfaces[seq]
136 label = substr(interface, 1, 1)
137 if (addrs[interface]) {
138 curr_read = io[interface, "r"]
139 curr_write = io[interface, "w"]
141 prefix = ENVIRON["HOME"] "/var/run/status/io_net_" interface
142 prev_read_file = prefix "_read"
143 prev_write_file = prefix "_write"
145 getline prev_read < prev_read_file
146 getline prev_write < prev_write_file
148 diff_read = (curr_read - prev_read ) / bytes_per_unit
149 diff_written = (curr_write - prev_write) / bytes_per_unit
151 print curr_read > prev_read_file
152 print curr_write > prev_write_file
154 io_stat = sprintf("%0.3f▲ %0.3f▼", diff_written, diff_read)
155 if (interface ~ "^w") {
156 label = label ":" wifi_conn
161 number_of_interfaces_to_show = \
163 prefixes_of_interfaces_to_show,\
164 array_of_prefixes_of_interfaces_to_show,\
167 for (n = 1; n <= number_of_interfaces_to_show; n++) {
168 prefix = array_of_prefixes_of_interfaces_to_show[n]
169 if (interface ~ ("^" prefix)) {
170 if (++count_printed > 1) {
175 printf("%s%s:%s", sep, label, io_stat)
187 /^ +percentage: +/ {percentage=$2}
188 /^ +state: +/ {state=$2}
190 if (state == "discharging") {
191 direction_of_change = "<"
192 } else if (state == "charging") {
193 direction_of_change = ">"
195 direction_of_change = "="
197 printf("%s%s", direction_of_change, percentage)
200 datetime
=$
(date +'%a %b %d %H:%M:%S')
202 # date +'%a %u %b %d %H:%M:%S' \
212 # for (i=1; i<=7; i++) {
213 # if (i == 6 || i == 4) {
219 # if (i == wday_seq) {
220 # #symbol = substr(wday_name, 1, 1)
222 # } else if (i < wday_seq){
227 # week = week sep symbol
230 # print "["week"]", month, mday, time;
236 # amixer get Master \
241 # sub("^\\[", "", level);
242 # sub("\\]$", "", level);
248 # amixer get Master \
250 # | awk '{print $4}' \
261 for (i=2; i<=NF; i++) printf(" %s", $i);
264 /^[ \t]*Mute:/ {mute = $2}
265 /^[ \t]*front-left:/ {left = $4}
266 /^[ \t]*front-right:/ {right = $4}
271 printf("%s %s", left, right)
277 volume
="($volume_pactl)"
280 max
=$
(cat /sys
/class
/backlight
/acpi_video
0/max_brightness
)
281 cur
=$
(cat /sys
/class
/backlight
/acpi_video
0/brightness
)
282 awk -v max
=$max -v cur
=$cur 'BEGIN {printf("%d%%", cur/max*100)}'
286 # grep '^status:' /proc/acpi/ibm/bluetooth \
288 # $2 == "disabled" {printf "off"}
289 # $2 == "enabled" {printf "on"}
294 echo -e 'show \n quit' \
299 controllers[++ctrl_count] = controller;
301 /^\t[A-Z][A-Za-z]+:/ {
305 for (i=3; i<=NF; i++) {
307 data[controller, key] = val;
310 # Using the 1st seen controller. Should we select specific instead?
311 power_status = data[controllers[1], "Powered"];
312 if (ctrl_count > 0) {
313 if (power_status == "no") {
315 } else if (power_status == "yes") {
318 printf("Unexpected bluetooth power status: %s\n", power_status)\
320 power_status = "ERROR"
323 power_status = "off" # TODO: Perhaps use differentiated marker?
325 printf("%s", power_status);
330 # xinput list-props 12 \
332 # /^\tDevice Enabled \([0-9]+\):/ {
334 # printf("%s", status);
339 #color_on_bg_gray='\033[m\033[40m'
341 energy_direction
=$
(echo "$energy" | cut
-b 1)
342 energy_percentage
=$
(echo "$energy" |
tr -d '<>=%')
343 if [[ "$energy_direction" = '<' ]]
345 if [[ $energy_percentage -le 5 ]]
347 DISPLAY
=:0.0 notify-send \
349 "Energy CRITICALLY low: $energy" \
350 'CHARGE NOW!!! GO GO GO!!!'
351 elif [[ $energy_percentage -le 10 ]]
353 DISPLAY
=:0.0 notify-send \
355 "Energy VERY low: $energy" \
357 elif [[ $energy_percentage -le 15 ]]
359 DISPLAY
=:0.0 notify-send \
361 "Energy low: $energy" \
363 elif [[ $energy_percentage -le 50 ]]
365 if [[ ! -a "$STATUS_FILE__ENERGY_NOTIFIED_BELLOW_HALF" ]]
367 DISPLAY
=:0.0 notify-send \
369 "Energy bellow half: $energy" \
370 'Where is the charger?'
371 touch "$STATUS_FILE__ENERGY_NOTIFIED_BELLOW_HALF"
375 rm -f "$STATUS_FILE__ENERGY_NOTIFIED_BELLOW_HALF"
378 weather
=$
(awk 'NR == 1 {printf("%s°F", $1)}' ~
/var
/run
/metar-KJFK-decoded-temp-fahrenheit
)
380 #signal_last_msg_age=$(
381 # ls -lt --time-style=+%s $HOME/var/lib/signal/latest_message.json \
382 # | awk -v now_seconds=$(date +%s) \
384 # mtime_seconds = $6;
385 # seconds = now_seconds - mtime_seconds;
386 # minutes = seconds / 60;
387 # hours = minutes / 60;
390 # months = days / 30;
393 # printf(fmt " s\n", seconds);
394 # printf(fmt " m\n", minutes);
395 # printf(fmt " h\n", hours);
396 # printf(fmt " d\n", days);
397 # printf(fmt " w\n", weeks);
398 # printf(fmt " mo\n", months);
408 | nc
127.0.0.1 6600 \
409 |
awk -v max_chars
=10 '
417 for (i=3; i<=NF; i++) {val = val " " $i}
423 title = data["Title:"]
431 last = split(file, parts, "/")
437 printf("%s", substr(out, 1, max_chars))
444 | nc
127.0.0.1 6600 \
446 -v current_song
="$mpd_currentsong" \
452 /^time: +[0-9]+:[0-9]+$/ {
454 seconds_current = time[1]
455 seconds_total = time[2]
457 hours = int(seconds_current / 60 / 60);
458 secs_beyond_hours = seconds_current - (hours * 60 * 60);
459 mins = int(secs_beyond_hours / 60);
460 secs = secs_beyond_hours - (mins * 60);
462 current_time = sprintf("%d:%.2d:%.2d", hours, mins, secs)
464 current_time = sprintf("%.2d:%.2d", mins, secs)
467 if (seconds_total > 0) {
468 time_percentage = (seconds_current / seconds_total) * 100
469 current_percentage = sprintf("%d%%", time_percentage)
471 current_percentage = "~"
475 function print_known_state(symbol) {
478 symbol, current_time, current_percentage, current_song \
482 function print_unknown_state(symbol) {
487 state = status["state:"]
489 if (state == "play") {
490 print_known_state("▶")
491 } else if (state == "pause") {
492 print_known_state("❚❚")
493 } else if (state == "stop") {
494 print_known_state("⬛")
496 print_unknown_state("--")
504 #--format=csv,noheader,nounits \
505 #--query-gpu=memory.total,memory.used,temperature.gpu \
511 #mem_used_percent = (100 * mem_used) / mem_total;
512 #printf("[%d%% %dC]", mem_used_percent, temp);
523 C=[$load ${temp}°C ${fan}rpm]\