nix/home-manager/hosts/nixos-laptop/desktops/hyprland/gruvbox/waybar/scripts/waybar-scripts.nix
2023-08-28 20:35:07 +09:00

26 lines
No EOL
1,021 B
Nix

{...}: {
home.file = {
".config/waybar/scripts/tailscale.sh" = {
enable = true;
executable = true;
text = ''
#!/usr/bin/env bash
CLASS=`tailscale status --json | jq -r '.BackendState'`
# 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
IP=`tailscale status --json | jq -r '.TailscaleIPs[0]'`
ALT="IP: $IP"
printf '{"class": %s", "alt": %s}' "$CLASS", "$ALT"
fi
if [ $CLASS == "Stopped" ]; then
ALT="Tailscale is not running"
printf '{"class": %s", "alt": %s}' "$CLASS", "$ALT"
fi
'';
};
};
}