From 742ce27e019b5f851b50822b68d09fc37502294b Mon Sep 17 00:00:00 2001 From: notgne2 Date: Sun, 6 Nov 2022 15:43:29 -0700 Subject: [PATCH] Don't show weather errors --- home-manager/modules/ezpcusr.nix | 23 ++++++++++++++++++----- 1 file changed, 18 insertions(+), 5 deletions(-) diff --git a/home-manager/modules/ezpcusr.nix b/home-manager/modules/ezpcusr.nix index 258ba4f..64e2f8b 100644 --- a/home-manager/modules/ezpcusr.nix +++ b/home-manager/modules/ezpcusr.nix @@ -372,11 +372,14 @@ in { target = lib.mkDefault "sway-session.target"; }; - settings.mainbar = { + settings.mainbar = let + weatherCommand = f: "${pkgs.curl}/bin/curl 'wttr.in/${cfg.location}?format=${f}' || echo 'ERR'"; + weatherIf = "(${pkgs.curl}/bin/curl 'wttr.in/${cfg.location}?format=%t' || echo 'ERR') | grep -c 'ERR|Unknown'"; + in { position = lib.mkDefault "left"; height = lib.mkDefault null; - modules-left = ["sway/workspaces" "custom/spacer" "custom/weather-temp" "custom/weather-precip" "custom/weather-wind"]; + modules-left = ["sway/workspaces" "custom/weather-spacer" "custom/weather-temp" "custom/weather-precip" "custom/weather-wind"]; modules-center = ["clock#1" "clock#2" "custom/spacer" "custom/media" "custom/spacer" "clock#3" "custom/spacer" "clock#4"]; modules-right = ["pulseaudio" "custom/spacer" "memory" "custom/spacer" "cpu"] ++ lib.optionals cfg.battery ["custom/spacer" "battery"] ++ ["custom/spacer" "tray"]; @@ -386,20 +389,30 @@ in { tooltip = lib.mkDefault false; }; + "custom/weather-spacer" = { + exec-if = weatherIf; + format = lib.mkDefault "〜"; + rotate = lib.mkDefault 90; + tooltip = lib.mkDefault false; + }; + "custom/weather-temp" = { - exec = lib.mkDefault "${pkgs.curl}/bin/curl 'wttr.in/${cfg.location}?format=%c+%t' || echo ERR"; + exec = lib.mkDefault (weatherCommand "%t+%c"); + exec-if = weatherIf; on-click = lib.mkDefault "${pkgs.xdg-utils}/bin/xdg-open 'https://weather.com/weather/today/l/85625'"; on-click-right = lib.mkDefault "${pkgs.xdg-utils}/bin/xdg-open 'https://wttr.in/${cfg.location}'"; interval = lib.mkDefault 900; }; "custom/weather-precip" = { - exec = lib.mkDefault "${pkgs.curl}/bin/curl 'wttr.in/${cfg.location}?format=🌧️+%p'"; + exec = lib.mkDefault (weatherCommand "🌧️+%p"); + exec-if = weatherIf; on-click = lib.mkDefault "${pkgs.xdg-utils}/bin/xdg-open 'https://www.lightningmaps.org/'"; on-click-right = "lib.mkDefault ${pkgs.xdg-utils}/bin/xdg-open 'https://wttr.in/${cfg.location}'"; interval = lib.mkDefault 900; }; "custom/weather-wind" = { - exec = lib.mkDefault "${pkgs.curl}/bin/curl 'wttr.in/${cfg.location}?format=🌬️+%w'"; + exec = lib.mkDefault (weatherCommand "🌬️+%w"); + exec-if = weatherIf; on-click = lib.mkDefault "${pkgs.xdg-utils}/bin/xdg-open 'https://www.ventusky.com/"; on-click-right = lib.mkDefault "${pkgs.xdg-utils}/bin/xdg-open 'https://wttr.in/${cfg.location}'"; interval = lib.mkDefault 900;