Move screen device name to a global constant
[khatus.git] / bin / khatus_show
index eebac64..dd59b14 100755 (executable)
@@ -6,6 +6,10 @@ BIN=$HOME/bin
 STATUS_DIR=$HOME/var/run/status
 STATUS_FILE__WIFI=$STATUS_DIR/wifi
 STATUS_FILE__ENERGY_NOTIFIED_BELLOW_HALF=$STATUS_DIR/notified_energy_bellow_half
+DISK_IO_DEVICE='dm-1'
+DISK_SPACE_DEVICE='/dev/mapper/kubuntu--vg-root'
+SCREEN_DEVICE='acpi_video0'
+
 
 load=$(awk '{printf("%4.2f", $1)}' /proc/loadavg)
 
@@ -69,15 +73,18 @@ disk_io=$(
             printf("%0.3f▲ %0.3f▼\n", diff_write, diff_read);
 
         }
-        ' /sys/block/dm-1/stat
+        ' "/sys/block/$DISK_IO_DEVICE/stat"
 )
 
 disk=$(
     df \
-    | awk -v disk_io="$disk_io" '
+    | awk \
+        -v disk_io="$disk_io" \
+        -v device="$DISK_SPACE_DEVICE" \
+        '
         function round(n) {return int(n + 0.5)}
 
-        $1 == "/dev/mapper/kubuntu--vg-root" {
+        $1 == device {
             curr_perc = $5; sub("%$", "", curr_perc);
             prev_perc_file = ENVIRON["HOME"] "/var/run/status/disk_space_used";
             getline prev_perc   < prev_perc_file;
@@ -92,9 +99,13 @@ disk=$(
             printf("%s[%d%% %s]", direction, curr_perc, disk_io);
         }')
 
+# TODO: Wi-Fi status file should be a file per-wifi-device
 network=$(
     ip -s addr \
-    | awk -v wifi_conn="$(cat $STATUS_FILE__WIFI)" '
+    | awk \
+        -v wifi_conn="$(cat $STATUS_FILE__WIFI)" \
+        -v prefixes_of_interfaces_to_show='w' \
+        '
         BEGIN {
             bytes_per_unit = 1024 * 1024
         }
@@ -121,11 +132,8 @@ network=$(
         }
 
         END {
-            excluded["lo"]++
-            excluded["enp0s25"]++
-
-            for (i=1; i<=sequence; i++) {
-                interface = interfaces[i]
+            for (seq=1; seq<=sequence; seq++) {
+                interface = interfaces[seq]
                 label = substr(interface, 1, 1)
                 if (addrs[interface]) {
                     curr_read  = io[interface, "r"]
@@ -145,19 +153,28 @@ network=$(
                     print curr_write > prev_write_file
 
                     io_stat = sprintf("%0.3f▲ %0.3f▼", diff_written, diff_read)
-                    if (interface == "wlp3s0") {
+                    if (interface ~ "^w") {
                         label = label ":" wifi_conn
                     }
                 } else {
                     io_stat = "--"
                 }
-                if (!(interface in excluded)) {
-                    if (++count_printed > 1) {
-                        sep = "  "
-                    } else {
-                        sep = ""
+                number_of_interfaces_to_show = \
+                    split(\
+                        prefixes_of_interfaces_to_show,\
+                        array_of_prefixes_of_interfaces_to_show,\
+                        " +"\
+                    )
+                for (n = 1; n <= number_of_interfaces_to_show; n++) {
+                    prefix = array_of_prefixes_of_interfaces_to_show[n]
+                    if (interface ~ ("^" prefix)) {
+                        if (++count_printed > 1) {
+                            sep = "  "
+                        } else {
+                            sep = ""
+                        }
+                        printf("%s%s:%s", sep, label, io_stat)
                     }
-                    printf("%s%s:%s", sep, label, io_stat)
                 }
             }
         }'
@@ -261,8 +278,8 @@ volume_pactl=$(
 volume="($volume_pactl)"
 
 screen_brightness=$(
-    max=$(cat /sys/class/backlight/acpi_video0/max_brightness)
-    cur=$(cat /sys/class/backlight/acpi_video0/brightness)
+    max=$(cat /sys/class/backlight/"$SCREEN_DEVICE"/max_brightness)
+    cur=$(cat /sys/class/backlight/"$SCREEN_DEVICE"/brightness)
     awk -v max=$max -v cur=$cur 'BEGIN {printf("%d%%", cur/max*100)}'
 )
 
This page took 0.039016 seconds and 4 git commands to generate.