nix/home-manager/common/desktops/hyprland/assets/waybar/scripts.nix

27 lines
1.1 KiB
Nix
Raw Normal View History

2023-08-28 19:35:59 +09:00
{...}: {
home.file = {
".config/waybar/scripts/tailscale.sh" = {
enable = true;
executable = true;
text = ''
2023-08-28 20:35:07 +09:00
#!/usr/bin/env bash
2023-11-12 22:45:05 +09:00
CLASS=`tailscale status --json | fx . '.BackendState'`
2023-08-28 20:35:07 +09:00
# Known values: Running, Stopped
# Expected Output:
# {"text": "$text", "alt": "$alt", "tooltip": "$tooltip", "class": "$class", "percentage": $percentage }
# Different $Class depending on if TS is running or not
if [ $CLASS == "Running" ]; then
2023-11-12 22:45:05 +09:00
IP=`tailscale status --json | fx . '.TailscaleIPs[0]'`
2023-08-28 20:44:27 +09:00
TOOLTIP="IP: $IP"
2023-08-28 20:52:07 +09:00
printf '{"class": "%s", "tooltip": "%s", "alt": "%s"}\n' "$CLASS" "$TOOLTIP" "$CLASS"
2023-08-28 20:35:07 +09:00
fi
if [ $CLASS == "Stopped" ]; then
2023-08-28 20:44:27 +09:00
TOOLTIP="Tailscale is not running"
2023-08-28 20:52:07 +09:00
printf '{"class": "%s", "tooltip": "%s", "alt": "%s"}\n' "$CLASS" "$TOOLTIP" "$CLASS"
2023-08-28 20:35:07 +09:00
fi
2023-08-28 19:35:59 +09:00
'';
2023-08-28 19:39:04 +09:00
};
};
2023-11-12 22:45:05 +09:00
}