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:" opt
13 SCREEN_BRIGHTNESS_DEVICE_NAME
="$OPTARG"
16 DISK_IO_DEVICE
="$OPTARG"
19 DISK_SPACE_DEVICE
="$OPTARG"
22 echo "Unknown option: $OPTARG" >&2
26 echo "Missing argument for option: $OPTARG" >&2
31 if [ "$SCREEN_BRIGHTNESS_DEVICE_NAME" == '' ]; then echo 'Missing -b' >&2; exit 1; fi
32 if [ "$DISK_IO_DEVICE" == '' ]; then echo 'Missing -d' >&2; exit 1; fi
33 if [ "$DISK_SPACE_DEVICE" == '' ]; then echo 'Missing -s' >&2; exit 1; fi
34 SCREEN_BRIGHTNESS_DEVICE_PATH
="/sys/class/backlight/$SCREEN_BRIGHTNESS_DEVICE_NAME"
37 load
=$
(awk '{printf("%4.2f", $1)}' /proc
/loadavg
)
39 fan
=$
(awk '/^speed:/ {printf "%4d", $2}' /proc
/acpi
/ibm
/fan
)
41 #cpu=$($BIN/khatus_cpu_usage_from_proc_since_last_check)
46 function round(n) {return int(n + 0.5)}
52 prev_file = ENVIRON["HOME"] "/var/run/status/memory_used_percentage";
53 curr = round(used / total * 100);
54 getline prev < prev_file;
55 print curr > prev_file;
58 } else if (curr < prev) {
63 printf("%s%d%%", direction, curr);
66 temp
=$
(awk 'NR == 1 {print $1 / 1000}' /sys
/class
/thermal
/thermal_zone
0/temp
)
71 bytes_per_sector = 512
72 bytes_per_unit = 1024 * 1024
74 curr_sectors_read = $3
75 curr_sectors_write = $7
77 prev_file_prefix = ENVIRON["HOME"] "/var/run/status/disk_io"
78 prev_sectors_read_file = prev_file_prefix "_sectors_read"
79 prev_sectors_write_file = prev_file_prefix "_sectors_write"
81 getline prev_sectors_read < prev_sectors_read_file
82 getline prev_sectors_write < prev_sectors_write_file
84 diff_read_sectors = (curr_sectors_read - prev_sectors_read)
85 diff_write_sectors = (curr_sectors_write - prev_sectors_write)
87 diff_read_bytes = diff_read_sectors * bytes_per_sector
88 diff_write_bytes = diff_write_sectors * bytes_per_sector
90 diff_read = diff_read_bytes / bytes_per_unit
91 diff_write = diff_write_bytes / bytes_per_unit
93 print curr_sectors_read > prev_sectors_read_file
94 print curr_sectors_write > prev_sectors_write_file
96 printf("%0.3f▲ %0.3f▼\n", diff_write, diff_read);
99 ' "/sys/block/$DISK_IO_DEVICE/stat"
105 -v disk_io
="$disk_io" \
106 -v device
="$DISK_SPACE_DEVICE" \
108 function round(n) {return int(n + 0.5)}
111 curr_perc = $5; sub("%$", "", curr_perc);
112 prev_perc_file = ENVIRON["HOME"] "/var/run/status/disk_space_used";
113 getline prev_perc < prev_perc_file;
114 print curr_perc > prev_perc_file;
115 if (curr_perc > prev_perc) {
117 } else if (curr_perc < prev_perc) {
122 printf("%s[%d%% %s]", direction, curr_perc, disk_io);
125 # TODO: Wi-Fi status file should be a file per-wifi-device
129 -v wifi_conn
="$(cat $STATUS_FILE__WIFI)" \
130 -v prefixes_of_interfaces_to_show
='w' \
133 bytes_per_unit = 1024 * 1024
141 interfaces[sequence] = interface
145 sub("/[0-9]+", "", $2)
147 addrs[interface] = addr
150 /^ +RX: / {transfer_direction = "r"}
151 /^ +TX: / {transfer_direction = "w"}
153 /^ +[0-9]+ +[0-9]+ +[0-9]+ +[0-9]+ +[0-9]+ +[0-9]+ *$/ {
154 io[interface, transfer_direction] = $1;
158 for (seq=1; seq<=sequence; seq++) {
159 interface = interfaces[seq]
160 label = substr(interface, 1, 1)
161 if (addrs[interface]) {
162 curr_read = io[interface, "r"]
163 curr_write = io[interface, "w"]
165 prefix = ENVIRON["HOME"] "/var/run/status/io_net_" interface
166 prev_read_file = prefix "_read"
167 prev_write_file = prefix "_write"
169 getline prev_read < prev_read_file
170 getline prev_write < prev_write_file
172 diff_read = (curr_read - prev_read ) / bytes_per_unit
173 diff_written = (curr_write - prev_write) / bytes_per_unit
175 print curr_read > prev_read_file
176 print curr_write > prev_write_file
178 io_stat = sprintf("%0.3f▲ %0.3f▼", diff_written, diff_read)
179 if (interface ~ "^w") {
180 label = label ":" wifi_conn
185 number_of_interfaces_to_show = \
187 prefixes_of_interfaces_to_show,\
188 array_of_prefixes_of_interfaces_to_show,\
191 for (n = 1; n <= number_of_interfaces_to_show; n++) {
192 prefix = array_of_prefixes_of_interfaces_to_show[n]
193 if (interface ~ ("^" prefix)) {
194 if (++count_printed > 1) {
199 printf("%s%s:%s", sep, label, io_stat)
211 /^ +percentage: +/ {percentage=$2}
212 /^ +state: +/ {state=$2}
214 if (state == "discharging") {
215 direction_of_change = "<"
216 } else if (state == "charging") {
217 direction_of_change = ">"
219 direction_of_change = "="
221 printf("%s%s", direction_of_change, percentage)
224 datetime
=$
(date +'%a %b %d %H:%M:%S')
226 # date +'%a %u %b %d %H:%M:%S' \
236 # for (i=1; i<=7; i++) {
237 # if (i == 6 || i == 4) {
243 # if (i == wday_seq) {
244 # #symbol = substr(wday_name, 1, 1)
246 # } else if (i < wday_seq){
251 # week = week sep symbol
254 # print "["week"]", month, mday, time;
260 # amixer get Master \
265 # sub("^\\[", "", level);
266 # sub("\\]$", "", level);
272 # amixer get Master \
274 # | awk '{print $4}' \
285 for (i=2; i<=NF; i++) printf(" %s", $i);
288 /^[ \t]*Mute:/ {mute = $2}
289 /^[ \t]*front-left:/ {left = $4}
290 /^[ \t]*front-right:/ {right = $4}
295 printf("%s %s", left, right)
301 volume
="($volume_pactl)"
305 $
(cat $SCREEN_BRIGHTNESS_DEVICE_PATH/brightness
)
306 / $
(cat $SCREEN_BRIGHTNESS_DEVICE_PATH/max_brightness
)
312 # grep '^status:' /proc/acpi/ibm/bluetooth \
314 # $2 == "disabled" {printf "off"}
315 # $2 == "enabled" {printf "on"}
320 echo -e 'show \n quit' \
325 controllers[++ctrl_count] = controller;
327 /^\t[A-Z][A-Za-z]+:/ {
331 for (i=3; i<=NF; i++) {
333 data[controller, key] = val;
336 # Using the 1st seen controller. Should we select specific instead?
337 power_status = data[controllers[1], "Powered"];
338 if (ctrl_count > 0) {
339 if (power_status == "no") {
341 } else if (power_status == "yes") {
344 printf("Unexpected bluetooth power status: %s\n", power_status)\
346 power_status = "ERROR"
349 power_status = "off" # TODO: Perhaps use differentiated marker?
351 printf("%s", power_status);
356 # xinput list-props 12 \
358 # /^\tDevice Enabled \([0-9]+\):/ {
360 # printf("%s", status);
365 #color_on_bg_gray='\033[m\033[40m'
367 energy_direction
=$
(echo "$energy" | cut
-b 1)
368 energy_percentage
=$
(echo "$energy" |
tr -d '<>=%')
369 if [[ "$energy_direction" = '<' ]]
371 if [[ $energy_percentage -le 5 ]]
373 DISPLAY
=:0.0 notify-send \
375 "Energy CRITICALLY low: $energy" \
376 'CHARGE NOW!!! GO GO GO!!!'
377 elif [[ $energy_percentage -le 10 ]]
379 DISPLAY
=:0.0 notify-send \
381 "Energy VERY low: $energy" \
383 elif [[ $energy_percentage -le 15 ]]
385 DISPLAY
=:0.0 notify-send \
387 "Energy low: $energy" \
389 elif [[ $energy_percentage -le 50 ]]
391 if [[ ! -a "$STATUS_FILE__ENERGY_NOTIFIED_BELLOW_HALF" ]]
393 DISPLAY
=:0.0 notify-send \
395 "Energy bellow half: $energy" \
396 'Where is the charger?'
397 touch "$STATUS_FILE__ENERGY_NOTIFIED_BELLOW_HALF"
401 rm -f "$STATUS_FILE__ENERGY_NOTIFIED_BELLOW_HALF"
404 weather
=$
(awk 'NR == 1 {printf("%s°F", $1)}' ~
/var
/run
/metar-KJFK-decoded-temp-fahrenheit
)
406 #signal_last_msg_age=$(
407 # ls -lt --time-style=+%s $HOME/var/lib/signal/latest_message.json \
408 # | awk -v now_seconds=$(date +%s) \
410 # mtime_seconds = $6;
411 # seconds = now_seconds - mtime_seconds;
412 # minutes = seconds / 60;
413 # hours = minutes / 60;
416 # months = days / 30;
419 # printf(fmt " s\n", seconds);
420 # printf(fmt " m\n", minutes);
421 # printf(fmt " h\n", hours);
422 # printf(fmt " d\n", days);
423 # printf(fmt " w\n", weeks);
424 # printf(fmt " mo\n", months);
434 | nc
127.0.0.1 6600 \
435 |
awk -v max_chars
=10 '
443 for (i=3; i<=NF; i++) {val = val " " $i}
449 title = data["Title:"]
457 last = split(file, parts, "/")
463 printf("%s", substr(out, 1, max_chars))
470 | nc
127.0.0.1 6600 \
472 -v current_song
="$mpd_currentsong" \
478 /^time: +[0-9]+:[0-9]+$/ {
480 seconds_current = time[1]
481 seconds_total = time[2]
483 hours = int(seconds_current / 60 / 60);
484 secs_beyond_hours = seconds_current - (hours * 60 * 60);
485 mins = int(secs_beyond_hours / 60);
486 secs = secs_beyond_hours - (mins * 60);
488 current_time = sprintf("%d:%.2d:%.2d", hours, mins, secs)
490 current_time = sprintf("%.2d:%.2d", mins, secs)
493 if (seconds_total > 0) {
494 time_percentage = (seconds_current / seconds_total) * 100
495 current_percentage = sprintf("%d%%", time_percentage)
497 current_percentage = "~"
501 function print_known_state(symbol) {
504 symbol, current_time, current_percentage, current_song \
508 function print_unknown_state(symbol) {
513 state = status["state:"]
515 if (state == "play") {
516 print_known_state("▶")
517 } else if (state == "pause") {
518 print_known_state("❚❚")
519 } else if (state == "stop") {
520 print_known_state("⬛")
522 print_unknown_state("--")
530 #--format=csv,noheader,nounits \
531 #--query-gpu=memory.total,memory.used,temperature.gpu \
537 #mem_used_percent = (100 * mem_used) / mem_total;
538 #printf("[%d%% %dC]", mem_used_percent, temp);
549 C=[$load ${temp}°C ${fan}rpm]\
557 *$screen_brightness%\