Quellcode durchsuchen

Add some more waybar stuff

Johan Rong vor 6 Monaten
Ursprung
Commit
b6c02123f2

+ 43 - 1
home/features/application/sway/scripts.nix

@@ -33,7 +33,7 @@
           VOL_PERC=$(awk -v n="$VOL_NUM" 'BEGIN {print int(n * 100)}')
 
           if [[ "$VOLUME_INFO" == *"[MUTED]"* ]]; then
-              RESULT="Muted ($VOL_PERC%)"
+              RESULT="M($VOL_PERC%)"
           else
               RESULT="$VOL_PERC%"
           fi
@@ -42,6 +42,48 @@
         '';
         executable = true;
       };
+      mic = {
+        target = ".config/waybar/mic.sh";
+        text = ''
+          VOLUME_INFO=$(wpctl get-volume @DEFAULT_AUDIO_SOURCE@)
+          VOL_NUM=$(echo "$VOLUME_INFO" | awk '{print $2}')
+          VOL_PERC=$(awk -v n="$VOL_NUM" 'BEGIN {print int(n * 100)}')
+
+          if [[ "$VOLUME_INFO" == *"[MUTED]"* ]]; then
+              RESULT="M($VOL_PERC%)"
+          else
+              RESULT="$VOL_PERC%"
+          fi
+
+          echo "{\"text\": \"$RESULT\"}"
+        '';
+        executable = true;
+      };
+      net = {
+        target = ".config/waybar/net.sh";
+        executable = true;
+        text = ''
+          #!/usr/bin/env bash
+
+          # Get default network interface
+          DEVICE=$(ip route | awk '/default/ {print $5; exit}')
+
+          if [[ -n "$DEVICE" ]]; then
+              # Get local IPv4 address
+              IP=$(ip -4 addr show "$DEVICE" | awk '/inet / {print $2}' | cut -d/ -f1 | head -n1)
+
+              if [[ -n "$IP" ]]; then
+                  RESULT="$DEVICE ($IP)"
+              else
+                  RESULT="$DEVICE (no ip)"
+              fi
+          else
+              RESULT="Disconnected"
+          fi
+
+          echo "{\"text\": \"$RESULT\"}"
+        '';
+      };
       mic-mute = {
         target = ".config/waybar/mic-mute.sh";
         text = ''

+ 15 - 1
home/features/application/sway/waybar.nix

@@ -15,7 +15,7 @@
         spacing = 5;
         modules-left = [ "custom/block_start" "sway/workspaces" "mpris" "custom/block_stop" "sway/mode" ];
         modules-center = [ "custom/block_start" "custom/clock" "custom/block_stop" ];
-        modules-right = [ "custom/block_start" "custom/memory" "custom/slash" "custom/volume" "custom/block_stop" "tray" ];
+        modules-right = [ "custom/block_start" "custom/net" "custom/slash" "custom/memory" "custom/slash" "custom/mic" "custom/volume" "custom/block_stop" "tray" ];
 
         "mpris" = {
           player = "spotify";
@@ -74,6 +74,20 @@
           restart-interval = 0;
         };
 
+        "custom/mic" = {
+          format = "<span color=\"#ACA69E\">mic:</span> {} ";
+          exec = "~/.config/waybar/mic.sh";
+          return-type = "json";
+          restart-interval = 0;
+        };
+
+        "custom/net" = {
+          format = "<span color=\"#ACA69E\">net:</span> {} ";
+          exec = "~/.config/waybar/net.sh";
+          return-type = "json";
+          restart-interval = 0;
+        };
+
         "custom/memory" = {
           format = "<span color=\"#ACA69E\">mem:</span> {} ";
           exec = "~/.config/waybar/memory.sh";