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 load
=$
(awk '{printf("%4.2f", $1)}' /proc
/loadavg
)
12 fan
=$
(awk '/^speed:/ {printf "%4d", $2}' /proc
/acpi
/ibm
/fan
)
14 cpu
=$
($BIN/khatus_cpu_usage_from_proc_since_last_check
)
19 function round(n) {return int(n + 0.5)}
25 prev_file = "/home/siraaj/var/run/status/memory_used_percentage";
26 curr = round(used / total * 100);
27 getline prev < prev_file;
28 print curr > prev_file;
31 } else if (curr < prev) {
36 printf("%s%d%%", direction, curr);
39 temp
=$
(awk 'NR == 1 {print $1 / 1000}' /sys
/class
/thermal
/thermal_zone
0/temp
)
44 bytes_per_sector = 512
45 bytes_per_unit = 1024 * 1024
47 curr_sectors_read = $3
48 curr_sectors_write = $7
50 prev_file_prefix = "/home/siraaj/var/run/status/disk_io"
51 prev_sectors_read_file = prev_file_prefix "_sectors_read"
52 prev_sectors_write_file = prev_file_prefix "_sectors_write"
54 getline prev_sectors_read < prev_sectors_read_file
55 getline prev_sectors_write < prev_sectors_write_file
57 diff_read_sectors = (curr_sectors_read - prev_sectors_read)
58 diff_write_sectors = (curr_sectors_write - prev_sectors_write)
60 diff_read_bytes = diff_read_sectors * bytes_per_sector
61 diff_write_bytes = diff_write_sectors * bytes_per_sector
63 diff_read = diff_read_bytes / bytes_per_unit
64 diff_write = diff_write_bytes / bytes_per_unit
66 print curr_sectors_read > prev_sectors_read_file
67 print curr_sectors_write > prev_sectors_write_file
69 printf("%0.3f▲ %0.3f▼\n", diff_write, diff_read);
72 ' /sys
/block
/dm-
1/stat
77 |
awk -v disk_io
="$disk_io" '
78 function round(n) {return int(n + 0.5)}
80 $1 == "/dev/mapper/kubuntu--vg-root" {
81 curr_perc = $5; sub("%$", "", curr_perc);
82 prev_perc_file = "/home/siraaj/var/run/status/disk_space_used";
83 getline prev_perc < prev_perc_file;
84 print curr_perc > prev_perc_file;
85 if (curr_perc > prev_perc) {
87 } else if (curr_perc < prev_perc) {
92 printf("%s[%d%% %s]", direction, curr_perc, disk_io);
96 awk -v wifi_conn
=$
(cat $STATUS_FILE__WIFI) '
98 bytes_per_unit = 1024 * 1024
102 device = $1; sub(":$", "", device);
106 prev_file_prefix = "/home/siraaj/var/run/status/io_net_" device;
107 prev_read_file = prev_file_prefix "_read";
108 prev_write_file = prev_file_prefix "_write";
110 getline prev_read < prev_read_file;
111 getline prev_write < prev_write_file;
113 diff_read = (curr_read - prev_read ) / bytes_per_unit;
114 diff_write = (curr_write - prev_write) / bytes_per_unit;
116 print curr_read > prev_read_file;
117 print curr_write > prev_write_file;
119 devices[device] = sprintf("%0.3f▲ %0.3f▼", diff_write, diff_read);
124 #eth = devices["enp0s25"]
125 wifi = devices["wlp3s0"]
126 printf("[%s | %s %s]", lo, wifi_conn, wifi)
136 /^ +percentage: +/ {percentage=$2}
137 /^ +state: +/ {state=$2}
139 if (state == "discharging") {
140 direction_of_change = "<"
141 } else if (state == "charging") {
142 direction_of_change = ">"
144 direction_of_change = "="
146 printf("%s%s", direction_of_change, percentage)
149 datetime
=$
(date +'%a, %b %d, %H:%M:%S')
152 # amixer get Master \
157 # sub("^\\[", "", level);
158 # sub("\\]$", "", level);
164 # amixer get Master \
166 # | awk '{print $4}' \
177 for (i=2; i<=NF; i++) printf(" %s", $i);
180 /^[ \t]*Mute:/ {mute = $2}
181 /^[ \t]*front-left:/ {left = $4}
182 /^[ \t]*front-right:/ {right = $4}
187 printf("%s %s", left, right)
193 volume
="[$volume_pactl]"
196 max
=$
(cat /sys
/class
/backlight
/acpi_video
0/max_brightness
)
197 cur
=$
(cat /sys
/class
/backlight
/acpi_video
0/brightness
)
198 awk -v max
=$max -v cur
=$cur 'BEGIN {printf("%d%%", cur/max*100)}'
202 # grep '^status:' /proc/acpi/ibm/bluetooth \
204 # $2 == "disabled" {printf "off"}
205 # $2 == "enabled" {printf "on"}
210 echo -e 'show \n quit' \
215 controllers[++ctrl_count] = controller;
217 /^\t[A-Z][A-Za-z]+:/ {
221 for (i=3; i<=NF; i++) {
223 data[controller, key] = val;
226 # Using the 1st seen controller. Should we select specific instead?
227 power_status = data[controllers[1], "Powered"];
228 if (ctrl_count > 0) {
229 if (power_status == "no") {
231 } else if (power_status == "yes") {
234 printf("Unexpected bluetooth power status: %s\n", power_status)\
236 power_status = "ERROR"
239 power_status = "off" # TODO: Perhaps use differentiated marker?
241 printf("%s", power_status);
246 # xinput list-props 12 \
248 # /^\tDevice Enabled \([0-9]+\):/ {
250 # printf("%s", status);
255 #color_on_bg_gray='\033[m\033[40m'
257 energy_direction
=$
(echo "$energy" | cut
-b 1)
258 energy_percentage
=$
(echo "$energy" |
tr -d '<>=%')
259 if [[ "$energy_direction" = '<' ]]
261 if [[ $energy_percentage -le 5 ]]
263 DISPLAY
=:0.0 notify-send \
265 "Energy CRITICALLY low: $energy" \
266 'CHARGE NOW!!! GO GO GO!!!'
267 elif [[ $energy_percentage -le 10 ]]
269 DISPLAY
=:0.0 notify-send \
271 "Energy VERY low: $energy" \
273 elif [[ $energy_percentage -le 15 ]]
275 DISPLAY
=:0.0 notify-send \
277 "Energy low: $energy" \
279 elif [[ $energy_percentage -le 50 ]]
281 if [[ ! -a "$STATUS_FILE__ENERGY_NOTIFIED_BELLOW_HALF" ]]
283 DISPLAY
=:0.0 notify-send \
285 "Energy bellow half: $energy" \
286 'Where is the charger?'
287 touch "$STATUS_FILE__ENERGY_NOTIFIED_BELLOW_HALF"
291 rm -f "$STATUS_FILE__ENERGY_NOTIFIED_BELLOW_HALF"
294 weather
=$
(awk 'NR == 1 {printf("%d°F", $1)}' ~
/var
/run
/metar-KJFK-decoded-temp-fahrenheit
)
296 signal_last_msg_age
=$
(
297 ls -lt --time-style=+%s
$HOME/var
/lib
/signal
/latest_message.json \
298 |
awk -v now_seconds
=$
(date +%s
) \
301 seconds = now_seconds - mtime_seconds;
302 minutes = seconds / 60;
303 hours = minutes / 60;
309 #printf(fmt " s\n", seconds);
310 printf(fmt " m\n", minutes);
311 printf(fmt " h\n", hours);
312 printf(fmt " d\n", days);
313 printf(fmt " w\n", weeks);
314 printf(fmt " mo\n", months);
324 | nc
127.0.0.1 6600 \
331 state = status["state:"]
333 if (state == "play") {
335 } else if (state == "pause") {
337 } else if (state == "stop") {
347 | nc
127.0.0.1 6600 \
348 |
awk -v max_chars
=10 '
351 for (i=3; i<=NF; i++) {file = file " " $i}
352 last = split(file, parts, "/")
353 print substr(parts[last], 1, max_chars)
366 C=[$cpu ${temp}°C ${fan}rpm]\
381 S=$screen_brightness\
386 [$mpd_state $mpd_current_file]\
388 $signal_last_msg_age\