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
9 while getopts ":b:d:s:i:" opt
13 SCREEN_BRIGHTNESS_DEVICE_NAME
="$OPTARG"
16 DISK_IO_DEVICE
="$OPTARG"
19 DISK_SPACE_DEVICE
="$OPTARG"
22 PREFIXES_OF_INTERFACES_TO_SHOW
="$OPTARG"
25 echo "Unknown option: $OPTARG" >&2
29 echo "Missing argument for option: $OPTARG" >&2
34 if [ "$SCREEN_BRIGHTNESS_DEVICE_NAME" == '' ]; then echo 'Missing -b' >&2; exit 1; fi
35 if [ "$DISK_IO_DEVICE" == '' ]; then echo 'Missing -d' >&2; exit 1; fi
36 if [ "$DISK_SPACE_DEVICE" == '' ]; then echo 'Missing -s' >&2; exit 1; fi
37 SCREEN_BRIGHTNESS_DEVICE_PATH
="/sys/class/backlight/$SCREEN_BRIGHTNESS_DEVICE_NAME"
40 load
=$
(awk '{printf("%4.2f", $1)}' /proc
/loadavg
)
42 fan
=$
(awk '/^speed:/ {printf "%4d", $2}' /proc
/acpi
/ibm
/fan
)
44 #cpu=$($BIN/khatus_cpu_usage_from_proc_since_last_check)
49 function round(n) {return int(n + 0.5)}
55 prev_file = ENVIRON["HOME"] "/var/run/status/memory_used_percentage";
56 curr = round(used / total * 100);
57 getline prev < prev_file;
58 print curr > prev_file;
61 } else if (curr < prev) {
66 printf("%s%d%%", direction, curr);
69 temp
=$
(awk 'NR == 1 {print $1 / 1000}' /sys
/class
/thermal
/thermal_zone
0/temp
)
74 bytes_per_sector = 512
75 bytes_per_unit = 1024 * 1024
77 curr_sectors_read = $3
78 curr_sectors_write = $7
80 prev_file_prefix = ENVIRON["HOME"] "/var/run/status/disk_io"
81 prev_sectors_read_file = prev_file_prefix "_sectors_read"
82 prev_sectors_write_file = prev_file_prefix "_sectors_write"
84 getline prev_sectors_read < prev_sectors_read_file
85 getline prev_sectors_write < prev_sectors_write_file
87 diff_read_sectors = (curr_sectors_read - prev_sectors_read)
88 diff_write_sectors = (curr_sectors_write - prev_sectors_write)
90 diff_read_bytes = diff_read_sectors * bytes_per_sector
91 diff_write_bytes = diff_write_sectors * bytes_per_sector
93 diff_read = diff_read_bytes / bytes_per_unit
94 diff_write = diff_write_bytes / bytes_per_unit
96 print curr_sectors_read > prev_sectors_read_file
97 print curr_sectors_write > prev_sectors_write_file
99 printf("%0.3f▲ %0.3f▼\n", diff_write, diff_read);
102 ' "/sys/block/$DISK_IO_DEVICE/stat"
108 -v disk_io
="$disk_io" \
109 -v device
="$DISK_SPACE_DEVICE" \
111 function round(n) {return int(n + 0.5)}
114 curr_perc = $5; sub("%$", "", curr_perc);
115 prev_perc_file = ENVIRON["HOME"] "/var/run/status/disk_space_used";
116 getline prev_perc < prev_perc_file;
117 print curr_perc > prev_perc_file;
118 if (curr_perc > prev_perc) {
120 } else if (curr_perc < prev_perc) {
125 printf("%s[%d%% %s]", direction, curr_perc, disk_io);
128 # TODO: Wi-Fi status file should be a file per-wifi-device
132 -v wifi_conn
="$(cat $STATUS_FILE__WIFI)" \
133 -v prefixes_of_interfaces_to_show
="$PREFIXES_OF_INTERFACES_TO_SHOW" \
136 bytes_per_unit = 1024 * 1024
144 interfaces[sequence] = interface
148 sub("/[0-9]+", "", $2)
150 addrs[interface] = addr
153 /^ +RX: / {transfer_direction = "r"}
154 /^ +TX: / {transfer_direction = "w"}
156 /^ +[0-9]+ +[0-9]+ +[0-9]+ +[0-9]+ +[0-9]+ +[0-9]+ *$/ {
157 io[interface, transfer_direction] = $1;
161 for (seq=1; seq<=sequence; seq++) {
162 interface = interfaces[seq]
163 label = substr(interface, 1, 1)
164 if (addrs[interface]) {
165 curr_read = io[interface, "r"]
166 curr_write = io[interface, "w"]
168 prefix = ENVIRON["HOME"] "/var/run/status/io_net_" interface
169 prev_read_file = prefix "_read"
170 prev_write_file = prefix "_write"
172 getline prev_read < prev_read_file
173 getline prev_write < prev_write_file
175 diff_read = (curr_read - prev_read ) / bytes_per_unit
176 diff_written = (curr_write - prev_write) / bytes_per_unit
178 print curr_read > prev_read_file
179 print curr_write > prev_write_file
181 io_stat = sprintf("%0.3f▲ %0.3f▼", diff_written, diff_read)
182 if (interface ~ "^w") {
183 label = label ":" wifi_conn
188 number_of_interfaces_to_show = \
190 prefixes_of_interfaces_to_show,\
191 array_of_prefixes_of_interfaces_to_show,\
194 for (n = 1; n <= number_of_interfaces_to_show; n++) {
195 prefix = array_of_prefixes_of_interfaces_to_show[n]
196 if (interface ~ ("^" prefix)) {
197 if (++count_printed > 1) {
202 printf("%s%s:%s", sep, label, io_stat)
214 /^ +percentage: +/ {percentage=$2}
215 /^ +state: +/ {state=$2}
217 if (state == "discharging") {
218 direction_of_change = "<"
219 } else if (state == "charging") {
220 direction_of_change = ">"
222 direction_of_change = "="
224 printf("%s%s", direction_of_change, percentage)
227 datetime
=$
(date +'%a %b %d %H:%M:%S')
229 # date +'%a %u %b %d %H:%M:%S' \
239 # for (i=1; i<=7; i++) {
240 # if (i == 6 || i == 4) {
246 # if (i == wday_seq) {
247 # #symbol = substr(wday_name, 1, 1)
249 # } else if (i < wday_seq){
254 # week = week sep symbol
257 # print "["week"]", month, mday, time;
263 # amixer get Master \
268 # sub("^\\[", "", level);
269 # sub("\\]$", "", level);
275 # amixer get Master \
277 # | awk '{print $4}' \
288 for (i=2; i<=NF; i++) printf(" %s", $i);
291 /^[ \t]*Mute:/ {mute = $2}
292 /^[ \t]*front-left:/ {left = $4}
293 /^[ \t]*front-right:/ {right = $4}
298 printf("%s %s", left, right)
304 volume
="($volume_pactl)"
308 $
(cat $SCREEN_BRIGHTNESS_DEVICE_PATH/brightness
)
309 / $
(cat $SCREEN_BRIGHTNESS_DEVICE_PATH/max_brightness
)
315 # grep '^status:' /proc/acpi/ibm/bluetooth \
317 # $2 == "disabled" {printf "off"}
318 # $2 == "enabled" {printf "on"}
323 echo -e 'show \n quit' \
328 controllers[++ctrl_count] = controller;
330 /^\t[A-Z][A-Za-z]+:/ {
334 for (i=3; i<=NF; i++) {
336 data[controller, key] = val;
339 # Using the 1st seen controller. Should we select specific instead?
340 power_status = data[controllers[1], "Powered"];
341 if (ctrl_count > 0) {
342 if (power_status == "no") {
344 } else if (power_status == "yes") {
347 printf("Unexpected bluetooth power status: %s\n", power_status)\
349 power_status = "ERROR"
352 power_status = "off" # TODO: Perhaps use differentiated marker?
354 printf("%s", power_status);
359 # xinput list-props 12 \
361 # /^\tDevice Enabled \([0-9]+\):/ {
363 # printf("%s", status);
368 #color_on_bg_gray='\033[m\033[40m'
370 energy_direction
=$
(echo "$energy" | cut
-b 1)
371 energy_percentage
=$
(echo "$energy" |
tr -d '<>=%')
372 if [[ "$energy_direction" = '<' ]]
374 if [[ $energy_percentage -le 5 ]]
376 DISPLAY
=:0.0 notify-send \
378 "Energy CRITICALLY low: $energy" \
379 'CHARGE NOW!!! GO GO GO!!!'
380 elif [[ $energy_percentage -le 10 ]]
382 DISPLAY
=:0.0 notify-send \
384 "Energy VERY low: $energy" \
386 elif [[ $energy_percentage -le 15 ]]
388 DISPLAY
=:0.0 notify-send \
390 "Energy low: $energy" \
392 elif [[ $energy_percentage -le 50 ]]
394 if [[ ! -a "$STATUS_FILE__ENERGY_NOTIFIED_BELLOW_HALF" ]]
396 DISPLAY
=:0.0 notify-send \
398 "Energy bellow half: $energy" \
399 'Where is the charger?'
400 touch "$STATUS_FILE__ENERGY_NOTIFIED_BELLOW_HALF"
404 rm -f "$STATUS_FILE__ENERGY_NOTIFIED_BELLOW_HALF"
407 weather
=$
(awk 'NR == 1 {printf("%s°F", $1)}' ~
/var
/run
/metar-KJFK-decoded-temp-fahrenheit
)
409 #signal_last_msg_age=$(
410 # ls -lt --time-style=+%s $HOME/var/lib/signal/latest_message.json \
411 # | awk -v now_seconds=$(date +%s) \
413 # mtime_seconds = $6;
414 # seconds = now_seconds - mtime_seconds;
415 # minutes = seconds / 60;
416 # hours = minutes / 60;
419 # months = days / 30;
422 # printf(fmt " s\n", seconds);
423 # printf(fmt " m\n", minutes);
424 # printf(fmt " h\n", hours);
425 # printf(fmt " d\n", days);
426 # printf(fmt " w\n", weeks);
427 # printf(fmt " mo\n", months);
437 | nc
127.0.0.1 6600 \
438 |
awk -v max_chars
=10 '
446 for (i=3; i<=NF; i++) {val = val " " $i}
452 title = data["Title:"]
460 last = split(file, parts, "/")
466 printf("%s", substr(out, 1, max_chars))
473 | nc
127.0.0.1 6600 \
475 -v current_song
="$mpd_currentsong" \
481 /^time: +[0-9]+:[0-9]+$/ {
483 seconds_current = time[1]
484 seconds_total = time[2]
486 hours = int(seconds_current / 60 / 60);
487 secs_beyond_hours = seconds_current - (hours * 60 * 60);
488 mins = int(secs_beyond_hours / 60);
489 secs = secs_beyond_hours - (mins * 60);
491 current_time = sprintf("%d:%.2d:%.2d", hours, mins, secs)
493 current_time = sprintf("%.2d:%.2d", mins, secs)
496 if (seconds_total > 0) {
497 time_percentage = (seconds_current / seconds_total) * 100
498 current_percentage = sprintf("%d%%", time_percentage)
500 current_percentage = "~"
504 function print_known_state(symbol) {
507 symbol, current_time, current_percentage, current_song \
511 function print_unknown_state(symbol) {
516 state = status["state:"]
518 if (state == "play") {
519 print_known_state("▶")
520 } else if (state == "pause") {
521 print_known_state("❚❚")
522 } else if (state == "stop") {
523 print_known_state("⬛")
525 print_unknown_state("--")
533 #--format=csv,noheader,nounits \
534 #--query-gpu=memory.total,memory.used,temperature.gpu \
540 #mem_used_percent = (100 * mem_used) / mem_total;
541 #printf("[%d%% %dC]", mem_used_percent, temp);
552 C=[$load ${temp}°C ${fan}rpm]\
560 *$screen_brightness%\