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

27 lines
No EOL
1.1 KiB
Nix

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