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);
103 |
awk -v wifi_conn
="$(cat $STATUS_FILE__WIFI)" '
105 bytes_per_unit = 1024 * 1024
113 interfaces[sequence] = interface
117 sub("/[0-9]+", "", $2)
119 addrs[interface] = addr
122 /^ +RX: / {transfer_direction = "r"}
123 /^ +TX: / {transfer_direction = "w"}
125 /^ +[0-9]+ +[0-9]+ +[0-9]+ +[0-9]+ +[0-9]+ +[0-9]+ *$/ {
126 io[interface, transfer_direction] = $1;
131 excluded["enp0s25"]++
133 for (i=1; i<=sequence; i++) {
134 interface = interfaces[i]
135 label = substr(interface, 1, 1)
136 if (addrs[interface]) {
137 curr_read = io[interface, "r"]
138 curr_write = io[interface, "w"]
140 prefix = ENVIRON["HOME"] "/var/run/status/io_net_" interface
141 prev_read_file = prefix "_read"
142 prev_write_file = prefix "_write"
144 getline prev_read < prev_read_file
145 getline prev_write < prev_write_file
147 diff_read = (curr_read - prev_read ) / bytes_per_unit
148 diff_written = (curr_write - prev_write) / bytes_per_unit
150 print curr_read > prev_read_file
151 print curr_write > prev_write_file
153 io_stat = sprintf("%0.3f▲ %0.3f▼", diff_written, diff_read)
154 if (interface == "wlp3s0") {
155 label = label ":" wifi_conn
160 if (!(interface in excluded)) {
161 if (++count_printed > 1) {
166 printf("%s%s:%s", sep, label, io_stat)
177 /^ +percentage: +/ {percentage=$2}
178 /^ +state: +/ {state=$2}
180 if (state == "discharging") {
181 direction_of_change = "<"
182 } else if (state == "charging") {
183 direction_of_change = ">"
185 direction_of_change = "="
187 printf("%s%s", direction_of_change, percentage)
190 datetime
=$
(date +'%a %b %d %H:%M:%S')
192 # date +'%a %u %b %d %H:%M:%S' \
202 # for (i=1; i<=7; i++) {
203 # if (i == 6 || i == 4) {
209 # if (i == wday_seq) {
210 # #symbol = substr(wday_name, 1, 1)
212 # } else if (i < wday_seq){
217 # week = week sep symbol
220 # print "["week"]", month, mday, time;
226 # amixer get Master \
231 # sub("^\\[", "", level);
232 # sub("\\]$", "", level);
238 # amixer get Master \
240 # | awk '{print $4}' \
251 for (i=2; i<=NF; i++) printf(" %s", $i);
254 /^[ \t]*Mute:/ {mute = $2}
255 /^[ \t]*front-left:/ {left = $4}
256 /^[ \t]*front-right:/ {right = $4}
261 printf("%s %s", left, right)
267 volume
="($volume_pactl)"
270 max
=$
(cat /sys
/class
/backlight
/acpi_video
0/max_brightness
)
271 cur
=$
(cat /sys
/class
/backlight
/acpi_video
0/brightness
)
272 awk -v max
=$max -v cur
=$cur 'BEGIN {printf("%d%%", cur/max*100)}'
276 # grep '^status:' /proc/acpi/ibm/bluetooth \
278 # $2 == "disabled" {printf "off"}
279 # $2 == "enabled" {printf "on"}
284 echo -e 'show \n quit' \
289 controllers[++ctrl_count] = controller;
291 /^\t[A-Z][A-Za-z]+:/ {
295 for (i=3; i<=NF; i++) {
297 data[controller, key] = val;
300 # Using the 1st seen controller. Should we select specific instead?
301 power_status = data[controllers[1], "Powered"];
302 if (ctrl_count > 0) {
303 if (power_status == "no") {
305 } else if (power_status == "yes") {
308 printf("Unexpected bluetooth power status: %s\n", power_status)\
310 power_status = "ERROR"
313 power_status = "off" # TODO: Perhaps use differentiated marker?
315 printf("%s", power_status);
320 # xinput list-props 12 \
322 # /^\tDevice Enabled \([0-9]+\):/ {
324 # printf("%s", status);
329 #color_on_bg_gray='\033[m\033[40m'
331 energy_direction
=$
(echo "$energy" | cut
-b 1)
332 energy_percentage
=$
(echo "$energy" |
tr -d '<>=%')
333 if [[ "$energy_direction" = '<' ]]
335 if [[ $energy_percentage -le 5 ]]
337 DISPLAY
=:0.0 notify-send \
339 "Energy CRITICALLY low: $energy" \
340 'CHARGE NOW!!! GO GO GO!!!'
341 elif [[ $energy_percentage -le 10 ]]
343 DISPLAY
=:0.0 notify-send \
345 "Energy VERY low: $energy" \
347 elif [[ $energy_percentage -le 15 ]]
349 DISPLAY
=:0.0 notify-send \
351 "Energy low: $energy" \
353 elif [[ $energy_percentage -le 50 ]]
355 if [[ ! -a "$STATUS_FILE__ENERGY_NOTIFIED_BELLOW_HALF" ]]
357 DISPLAY
=:0.0 notify-send \
359 "Energy bellow half: $energy" \
360 'Where is the charger?'
361 touch "$STATUS_FILE__ENERGY_NOTIFIED_BELLOW_HALF"
365 rm -f "$STATUS_FILE__ENERGY_NOTIFIED_BELLOW_HALF"
368 weather
=$
(awk 'NR == 1 {printf("%s°F", $1)}' ~
/var
/run
/metar-KJFK-decoded-temp-fahrenheit
)
370 #signal_last_msg_age=$(
371 # ls -lt --time-style=+%s $HOME/var/lib/signal/latest_message.json \
372 # | awk -v now_seconds=$(date +%s) \
374 # mtime_seconds = $6;
375 # seconds = now_seconds - mtime_seconds;
376 # minutes = seconds / 60;
377 # hours = minutes / 60;
380 # months = days / 30;
383 # printf(fmt " s\n", seconds);
384 # printf(fmt " m\n", minutes);
385 # printf(fmt " h\n", hours);
386 # printf(fmt " d\n", days);
387 # printf(fmt " w\n", weeks);
388 # printf(fmt " mo\n", months);
398 | nc
127.0.0.1 6600 \
399 |
awk -v max_chars
=10 '
407 for (i=3; i<=NF; i++) {val = val " " $i}
413 title = data["Title:"]
421 last = split(file, parts, "/")
427 printf("%s", substr(out, 1, max_chars))
434 | nc
127.0.0.1 6600 \
436 -v current_song
="$mpd_currentsong" \
442 /^time: +[0-9]+:[0-9]+$/ {
444 seconds_current = time[1]
445 seconds_total = time[2]
447 hours = int(seconds_current / 60 / 60);
448 secs_beyond_hours = seconds_current - (hours * 60 * 60);
449 mins = int(secs_beyond_hours / 60);
450 secs = secs_beyond_hours - (mins * 60);
452 current_time = sprintf("%d:%.2d:%.2d", hours, mins, secs)
454 current_time = sprintf("%.2d:%.2d", mins, secs)
457 if (seconds_total > 0) {
458 time_percentage = (seconds_current / seconds_total) * 100
459 current_percentage = sprintf("%d%%", time_percentage)
461 current_percentage = "~"
465 function print_known_state(symbol) {
468 symbol, current_time, current_percentage, current_song \
472 function print_unknown_state(symbol) {
477 state = status["state:"]
479 if (state == "play") {
480 print_known_state("▶")
481 } else if (state == "pause") {
482 print_known_state("❚❚")
483 } else if (state == "stop") {
484 print_known_state("⬛")
486 print_unknown_state("--")
494 #--format=csv,noheader,nounits \
495 #--query-gpu=memory.total,memory.used,temperature.gpu \
501 #mem_used_percent = (100 * mem_used) / mem_total;
502 #printf("[%d%% %dC]", mem_used_percent, temp);
513 C=[$load ${temp}°C ${fan}rpm]\