ironbar: Watch mullvad instead of polling

Fixes an issue where logs would be filled with mullvad status requests.
This commit is contained in:
Donovan Glover 2024-04-08 06:28:25 -04:00
parent 70e6bcc223
commit c62c7189a5
No known key found for this signature in database
GPG Key ID: EA7408A77AE1BE65

View File

@ -4,7 +4,9 @@ let
inherit (builtins) toJSON;
inherit (lib) singleton;
inherit (config.lib.stylix.colors) base00 base01 base04 base05 base09;
inherit (pkgs) ironbar;
inherit (pkgs) ironbar inotify-tools;
mullvadScript = "ironbar/mullvad.fish";
in
{
home.packages = [ ironbar ];
@ -25,9 +27,8 @@ in
{
type = "script";
on_click_left = "notify-send -t 2000 \"Mullvad\" \"Changing location...\" && mullvad relay set location any && mullvad relay set location us";
cmd = "mullvad status | choose 4.. | sed -e 's/Chicago.*//g' -e 's/Atlanta.*//g' -e 's/Miami.*//g' -e 's/Ashburn.*//g' -e 's/Boston.*//g' -e 's/Charlotte.*//g' -e 's/Cleveland.*//g' -e 's/Dallas.*//g' -e 's/Detroit.*//g' -e 's/Denver.*//g' -e 's/Honolulu.*//g' -e 's/Houston.*//g' -e 's/Jackson.*//g' -e 's/Los Angeles.*//g' -e 's/Louisville.*//g' -e 's/Milwaukee.*//g' -e 's/Minneapolis.*//g' -e 's/New York.*//g' -e 's/Oklahoma.*//g' -e 's/Philadelphia.*//g' -e 's/Phoenix.*//g' -e 's/Piscataway.*//g' -e 's/Portland.*//g' -e 's/Raleigh.*//g' -e 's/Richmond.*//g' -e 's/Salt Lake.*//g' -e 's/San Francisco.*//g' -e 's/San Jose.*//g' -e 's/Seattle.*//g' -e 's/Secaucus.*//g' -e 's/Sioux Falls.*//g' -e 's/St. Louis.*//g' -e 's/Stamford.*//g' -e 's/Washington.*//g'";
mode = "poll";
interval = 2500;
cmd = "~/.config/${mullvadScript}";
mode = "watch";
}
];
@ -158,4 +159,69 @@ in
padding-right: 1em;
}
'';
xdg.configFile.${mullvadScript} = {
executable = true;
text = /* fish */ ''
#!/usr/bin/env fish
function get_mullvad_status
if test -z "$inside"
set inside true
test -n "$initialized" && sleep 0.2
set MULLVAD (mullvad status)
set LOCATION (echo "$MULLVAD" | choose 4.. | sed \
-e 's/Ashburn.*//g' \
-e 's/Atlanta.*//g' \
-e 's/Boston.*//g' \
-e 's/Charlotte.*//g' \
-e 's/Chicago.*//g' \
-e 's/Cleveland.*//g' \
-e 's/Dallas.*//g' \
-e 's/Detroit.*//g' \
-e 's/Denver.*//g' \
-e 's/Honolulu.*//g' \
-e 's/Houston.*//g' \
-e 's/Jackson.*//g' \
-e 's/Los Angeles.*//g' \
-e 's/Louisville.*//g' \
-e 's/Miami.*//g' \
-e 's/Milwaukee.*//g' \
-e 's/Minneapolis.*//g' \
-e 's/New York.*//g' \
-e 's/Oklahoma.*//g' \
-e 's/Philadelphia.*//g' \
-e 's/Phoenix.*//g' \
-e 's/Piscataway.*//g' \
-e 's/Portland.*//g' \
-e 's/Raleigh.*//g' \
-e 's/Richmond.*//g' \
-e 's/Salt Lake.*//g' \
-e 's/San Francisco.*//g' \
-e 's/San Jose.*//g' \
-e 's/Seattle.*//g' \
-e 's/Secaucus.*//g' \
-e 's/Sioux Falls.*//g' \
-e 's/St. Louis.*//g' \
-e 's/Stamford.*//g' \
-e 's/Washington.*//g'
)
echo "$LOCATION"
set -e inside
end
end
get_mullvad_status
set initialized true
${inotify-tools}/bin/inotifywait -q -e close_write,moved_to,create -m /etc/mullvad-vpn |
while read directory events filename
get_mullvad_status
end
'';
};
}