From fe231d26b304a5510d0787ceb3fed7d2fb8c14bc Mon Sep 17 00:00:00 2001 From: Ingolf Wagner Date: Tue, 7 Jan 2020 16:32:19 +1300 Subject: [PATCH] wtf: further improvements --- system/desktop/wtf.nix | 61 +++++++++++++++++++++++++++++++++++------- 1 file changed, 52 insertions(+), 9 deletions(-) diff --git a/system/desktop/wtf.nix b/system/desktop/wtf.nix index 7dfc43c..fcf80f5 100644 --- a/system/desktop/wtf.nix +++ b/system/desktop/wtf.nix @@ -3,6 +3,38 @@ let unstable = import { }; + networkStatus = let + + q-online = '' + if ${pkgs.curl}/bin/curl -s google.com >/dev/null; then + echo 'status: online' + else + echo 'status: offline ' + fi + ''; + + q-wireless = '' + for dev in $( + ${pkgs.iw}/bin/iw dev \ + | ${pkgs.gnused}/bin/sed -n 's/^\s*Interface\s\+\([0-9a-z]\+\)$/\1/p' + ); do + inet=$(${pkgs.iproute}/bin/ip addr show $dev \ + | ${pkgs.gnused}/bin/sed -n 's/.*inet \([0-9]\+\.[0-9]\+\.[0-9]\+\.[0-9]\+\).*/\1/p') \ + || unset inet + ssid=$(${pkgs.iw}/bin/iw dev $dev link \ + | ${pkgs.gnused}/bin/sed -n 's/.*\tSSID: \(.*\)/\1/p' \ + | ${pkgs.coreutils}/bin/tr -d '\r') \ + || unset ssid + printf '%s: %s %s\n' $dev ''${inet+ $inet} ''${ssid+ $ssid} + done + ''; + + in pkgs.writers.writeBash "network-status" '' + ${q-wireless} + ${q-online} + ${pkgs.coreutils}/bin/uptime + ''; + taskNextWeek = pkgs.writers.writeDash "taskweek" '' ${pkgs.taskwarrior}/bin/task \ export \ @@ -183,15 +215,6 @@ let refreshInterval = 3600; }; - uptime = cmdRunner { - title = "uptime"; - cmd = "uptime"; - top = 3; - left = 1; - height = 1; - width = 3; - }; - active-users = cmdRunner { title = "users"; cmd = activeUsers; @@ -221,6 +244,26 @@ let width = 2; refreshInterval = 60; }; + + network-status = cmdRunner { + title = "network status"; + cmd = networkStatus; + top = 3; + left = 1; + height = 1; + width = 3; + refreshInterval = 60; + }; + + uptime = cmdRunner { + enabled = false; + title = "uptime"; + cmd = "uptime"; + top = 3; + left = 1; + height = 1; + width = 3; + }; }; }; };