From b5616501b2bffd4117a5322031b8cbf24d61991c Mon Sep 17 00:00:00 2001 From: Simon Bruder Date: Sun, 8 Nov 2020 16:03:13 +0100 Subject: [PATCH] home: Move waybar exec commands into scripts --- users/simon/modules/sway.nix | 23 ++++++++++++++++++++--- 1 file changed, 20 insertions(+), 3 deletions(-) diff --git a/users/simon/modules/sway.nix b/users/simon/modules/sway.nix index 2003034..6d668ec 100644 --- a/users/simon/modules/sway.nix +++ b/users/simon/modules/sway.nix @@ -273,8 +273,20 @@ in }; "custom/redshift" = { interval = 10; - exec = "systemctl --user show redshift | grep -q ActiveState=active && echo '{\"tooltip\": \"Redshift active\", \"class\": \"active\"}' || echo '{\"tooltip\": \"Redshift inactive\", \"class\": \"inactive\"}'"; - on-click = "systemctl --user show redshift | grep -q ActiveState=active && systemctl --user stop redshift || systemctl --user start redshift"; + exec = pkgs.writeShellScript "waybar-redshift-state" '' + if systemctl --user show redshift | grep -q ActiveState=active; then + echo '{"tooltip": "Redshift active", "class": "active"}' + else + echo '{"tooltip": "Redshift inactive", "class": "inactive"}' + fi + ''; + on-click = pkgs.writeShellScript "waybar-redshift-toggle" '' + if systemctl --user show redshift | grep -q ActiveState=active; then + systemctl --user stop redshift + else + systemctl --user start redshift + fi + ''; return-type = "json"; format = ""; tooltip = false; @@ -347,7 +359,12 @@ in }; "custom/vpn" = { interval = 10; - exec = "ip -j link | jq --unbuffered --compact-output '[[.[].ifname | select(. | startswith(\"mullvad\"))][] | split(\"-\")[1] + \" ${thinsp}\"] as $conns | { text: ($conns[0] // \"\"), class: (if $conns | length > 0 then \"connected\" else \"disconnected\" end) }'"; + exec = pkgs.writeShellScript "vpn-state" '' + ip -j link \ + | jq --unbuffered --compact-output ' + [[.[].ifname | select(. | startswith("mullvad"))][] | split("-")[1] + " ${thinsp}"] as $conns + | { text: ($conns[0] // ""), class: (if $conns | length > 0 then "connected" else "disconnected" end) }' + ''; return-type = "json"; format = "{}"; tooltip = false;