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:w:" 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 WEATHER_STATION_ID
="$OPTARG"
28 echo "Unknown option: $OPTARG" >&2
32 echo "Missing argument for option: $OPTARG" >&2
37 if [ "$SCREEN_BRIGHTNESS_DEVICE_NAME" == '' ]; then echo 'Missing -b' >&2; exit 1; fi
38 if [ "$DISK_IO_DEVICE" == '' ]; then echo 'Missing -d' >&2; exit 1; fi
39 if [ "$DISK_SPACE_DEVICE" == '' ]; then echo 'Missing -s' >&2; exit 1; fi
40 if [ "$WEATHER_STATION_ID" == '' ]; then echo 'Missing -w' >&2; exit 1; fi
41 SCREEN_BRIGHTNESS_DEVICE_PATH
="/sys/class/backlight/$SCREEN_BRIGHTNESS_DEVICE_NAME"
44 load
=$
(awk '{printf("%4.2f", $1)}' /proc
/loadavg
)
46 fan
=$
(awk '/^speed:/ {printf "%4d", $2}' /proc
/acpi
/ibm
/fan
)
48 #cpu=$($BIN/khatus_cpu_usage_from_proc_since_last_check)
53 function round(n) {return int(n + 0.5)}
59 prev_file = ENVIRON["HOME"] "/var/run/status/memory_used_percentage";
60 curr = round(used / total * 100);
61 getline prev < prev_file;
62 print curr > prev_file;
65 } else if (curr < prev) {
70 printf("%s%d%%", direction, curr);
73 temp
=$
(awk 'NR == 1 {print $1 / 1000}' /sys
/class
/thermal
/thermal_zone
0/temp
)
78 bytes_per_sector = 512
79 bytes_per_unit = 1024 * 1024
81 curr_sectors_read = $3
82 curr_sectors_write = $7
84 prev_file_prefix = ENVIRON["HOME"] "/var/run/status/disk_io"
85 prev_sectors_read_file = prev_file_prefix "_sectors_read"
86 prev_sectors_write_file = prev_file_prefix "_sectors_write"
88 getline prev_sectors_read < prev_sectors_read_file
89 getline prev_sectors_write < prev_sectors_write_file
91 diff_read_sectors = (curr_sectors_read - prev_sectors_read)
92 diff_write_sectors = (curr_sectors_write - prev_sectors_write)
94 diff_read_bytes = diff_read_sectors * bytes_per_sector
95 diff_write_bytes = diff_write_sectors * bytes_per_sector
97 diff_read = diff_read_bytes / bytes_per_unit
98 diff_write = diff_write_bytes / bytes_per_unit
100 print curr_sectors_read > prev_sectors_read_file
101 print curr_sectors_write > prev_sectors_write_file
103 printf("%0.3f▲ %0.3f▼\n", diff_write, diff_read);
106 ' "/sys/block/$DISK_IO_DEVICE/stat"
112 -v disk_io
="$disk_io" \
113 -v device
="$DISK_SPACE_DEVICE" \
115 function round(n) {return int(n + 0.5)}
118 curr_perc = $5; sub("%$", "", curr_perc);
119 prev_perc_file = ENVIRON["HOME"] "/var/run/status/disk_space_used";
120 getline prev_perc < prev_perc_file;
121 print curr_perc > prev_perc_file;
122 if (curr_perc > prev_perc) {
124 } else if (curr_perc < prev_perc) {
129 printf("%s[%d%% %s]", direction, curr_perc, disk_io);
132 # TODO: Wi-Fi status file should be a file per-wifi-device
136 -v wifi_conn
="$(cat $STATUS_FILE__WIFI)" \
137 -v prefixes_of_interfaces_to_show
="$PREFIXES_OF_INTERFACES_TO_SHOW" \
140 bytes_per_unit = 1024 * 1024
148 interfaces[sequence] = interface
152 sub("/[0-9]+", "", $2)
154 addrs[interface] = addr
157 /^ +RX: / {transfer_direction = "r"}
158 /^ +TX: / {transfer_direction = "w"}
160 /^ +[0-9]+ +[0-9]+ +[0-9]+ +[0-9]+ +[0-9]+ +[0-9]+ *$/ {
161 io[interface, transfer_direction] = $1;
165 for (seq=1; seq<=sequence; seq++) {
166 interface = interfaces[seq]
167 label = substr(interface, 1, 1)
168 if (addrs[interface]) {
169 curr_read = io[interface, "r"]
170 curr_write = io[interface, "w"]
172 prefix = ENVIRON["HOME"] "/var/run/status/io_net_" interface
173 prev_read_file = prefix "_read"
174 prev_write_file = prefix "_write"
176 getline prev_read < prev_read_file
177 getline prev_write < prev_write_file
179 diff_read = (curr_read - prev_read ) / bytes_per_unit
180 diff_written = (curr_write - prev_write) / bytes_per_unit
182 print curr_read > prev_read_file
183 print curr_write > prev_write_file
185 io_stat = sprintf("%0.3f▲ %0.3f▼", diff_written, diff_read)
186 if (interface ~ "^w") {
187 label = label ":" wifi_conn
192 number_of_interfaces_to_show = \
194 prefixes_of_interfaces_to_show,\
195 array_of_prefixes_of_interfaces_to_show,\
198 for (n = 1; n <= number_of_interfaces_to_show; n++) {
199 prefix = array_of_prefixes_of_interfaces_to_show[n]
200 if (interface ~ ("^" prefix)) {
201 if (++count_printed > 1) {
206 printf("%s%s:%s", sep, label, io_stat)
218 /^ +percentage: +/ {percentage=$2}
219 /^ +state: +/ {state=$2}
221 if (state == "discharging") {
222 direction_of_change = "<"
223 } else if (state == "charging") {
224 direction_of_change = ">"
226 direction_of_change = "="
228 printf("%s%s", direction_of_change, percentage)
231 datetime
=$
(date +'%a %b %d %H:%M:%S')
233 # date +'%a %u %b %d %H:%M:%S' \
243 # for (i=1; i<=7; i++) {
244 # if (i == 6 || i == 4) {
250 # if (i == wday_seq) {
251 # #symbol = substr(wday_name, 1, 1)
253 # } else if (i < wday_seq){
258 # week = week sep symbol
261 # print "["week"]", month, mday, time;
267 # amixer get Master \
272 # sub("^\\[", "", level);
273 # sub("\\]$", "", level);
279 # amixer get Master \
281 # | awk '{print $4}' \
292 for (i=2; i<=NF; i++) printf(" %s", $i);
295 /^[ \t]*Mute:/ {mute = $2}
296 /^[ \t]*front-left:/ {left = $4}
297 /^[ \t]*front-right:/ {right = $4}
302 printf("%s %s", left, right)
308 volume
="($volume_pactl)"
312 $
(cat $SCREEN_BRIGHTNESS_DEVICE_PATH/brightness
)
313 / $
(cat $SCREEN_BRIGHTNESS_DEVICE_PATH/max_brightness
)
319 # grep '^status:' /proc/acpi/ibm/bluetooth \
321 # $2 == "disabled" {printf "off"}
322 # $2 == "enabled" {printf "on"}
327 echo -e 'show \n quit' \
332 controllers[++ctrl_count] = controller;
334 /^\t[A-Z][A-Za-z]+:/ {
338 for (i=3; i<=NF; i++) {
340 data[controller, key] = val;
343 # Using the 1st seen controller. Should we select specific instead?
344 power_status = data[controllers[1], "Powered"];
345 if (ctrl_count > 0) {
346 if (power_status == "no") {
348 } else if (power_status == "yes") {
351 printf("Unexpected bluetooth power status: %s\n", power_status)\
353 power_status = "ERROR"
356 power_status = "off" # TODO: Perhaps use differentiated marker?
358 printf("%s", power_status);
363 # xinput list-props 12 \
365 # /^\tDevice Enabled \([0-9]+\):/ {
367 # printf("%s", status);
372 #color_on_bg_gray='\033[m\033[40m'
374 energy_direction
=$
(echo "$energy" | cut
-b 1)
375 energy_percentage
=$
(echo "$energy" |
tr -d '<>=%')
376 if [[ "$energy_direction" = '<' ]]
378 if [[ $energy_percentage -le 5 ]]
380 DISPLAY
=:0.0 notify-send \
382 "Energy CRITICALLY low: $energy" \
383 'CHARGE NOW!!! GO GO GO!!!'
384 elif [[ $energy_percentage -le 10 ]]
386 DISPLAY
=:0.0 notify-send \
388 "Energy VERY low: $energy" \
390 elif [[ $energy_percentage -le 15 ]]
392 DISPLAY
=:0.0 notify-send \
394 "Energy low: $energy" \
396 elif [[ $energy_percentage -le 50 ]]
398 if [[ ! -a "$STATUS_FILE__ENERGY_NOTIFIED_BELLOW_HALF" ]]
400 DISPLAY
=:0.0 notify-send \
402 "Energy bellow half: $energy" \
403 'Where is the charger?'
404 touch "$STATUS_FILE__ENERGY_NOTIFIED_BELLOW_HALF"
408 rm -f "$STATUS_FILE__ENERGY_NOTIFIED_BELLOW_HALF"
413 'NR == 1 {printf("%s°F", $1)}' \
414 "$HOME/var/run/metar-${WEATHER_STATION_ID}-decoded-temp-fahrenheit"
417 #signal_last_msg_age=$(
418 # ls -lt --time-style=+%s $HOME/var/lib/signal/latest_message.json \
419 # | awk -v now_seconds=$(date +%s) \
421 # mtime_seconds = $6;
422 # seconds = now_seconds - mtime_seconds;
423 # minutes = seconds / 60;
424 # hours = minutes / 60;
427 # months = days / 30;
430 # printf(fmt " s\n", seconds);
431 # printf(fmt " m\n", minutes);
432 # printf(fmt " h\n", hours);
433 # printf(fmt " d\n", days);
434 # printf(fmt " w\n", weeks);
435 # printf(fmt " mo\n", months);
444 echo 'currentsong\nclose' \
445 | nc
127.0.0.1 6600 \
446 |
awk -v max_chars
=10 '
454 for (i=3; i<=NF; i++) {val = val " " $i}
460 title = data["Title:"]
468 last = split(file, parts, "/")
474 printf("%s", substr(out, 1, max_chars))
480 echo 'status\nclose' \
481 | nc
127.0.0.1 6600 \
483 -v current_song
="$mpd_currentsong" \
489 /^time: +[0-9]+:[0-9]+$/ {
491 seconds_current = time[1]
492 seconds_total = time[2]
494 hours = int(seconds_current / 60 / 60);
495 secs_beyond_hours = seconds_current - (hours * 60 * 60);
496 mins = int(secs_beyond_hours / 60);
497 secs = secs_beyond_hours - (mins * 60);
499 current_time = sprintf("%d:%.2d:%.2d", hours, mins, secs)
501 current_time = sprintf("%.2d:%.2d", mins, secs)
504 if (seconds_total > 0) {
505 time_percentage = (seconds_current / seconds_total) * 100
506 current_percentage = sprintf("%d%%", time_percentage)
508 current_percentage = "~"
512 function print_known_state(symbol) {
515 symbol, current_time, current_percentage, current_song \
519 function print_unknown_state(symbol) {
524 state = status["state:"]
526 if (state == "play") {
527 print_known_state("▶")
528 } else if (state == "pause") {
529 print_known_state("❚❚")
530 } else if (state == "stop") {
531 print_known_state("⬛")
533 print_unknown_state("--")
541 #--format=csv,noheader,nounits \
542 #--query-gpu=memory.total,memory.used,temperature.gpu \
548 #mem_used_percent = (100 * mem_used) / mem_total;
549 #printf("[%d%% %dC]", mem_used_percent, temp);
560 C=[$load ${temp}°C ${fan}rpm]\
568 *$screen_brightness%\