From 72af419c43ec493d4cea7bb650897b358e5f3e4a Mon Sep 17 00:00:00 2001 From: Ruben Beltran del Rio Date: Tue, 8 Apr 2025 13:15:42 +0200 Subject: Make bar glyphier --- config/waybar/scripts/mullvad.sh | 38 +++++++++++++++++++++++++++++++++++++ config/waybar/scripts/tailscale.sh | 39 ++++++++++++++++++++++++++++++++++++++ 2 files changed, 77 insertions(+) create mode 100755 config/waybar/scripts/mullvad.sh create mode 100755 config/waybar/scripts/tailscale.sh (limited to 'config/waybar/scripts') diff --git a/config/waybar/scripts/mullvad.sh b/config/waybar/scripts/mullvad.sh new file mode 100755 index 0000000..f73cf5b --- /dev/null +++ b/config/waybar/scripts/mullvad.sh @@ -0,0 +1,38 @@ +#!/usr/bin/env bash + +STATUS_KEY="state" +RUNNING="connected" + +mullvad_status () { + status="$(mullvad status --json | jq -r '.'$STATUS_KEY)" + if [ "$status" = $RUNNING ]; then + return 0 + fi + return 1 +} + +toggle_status () { + if mullvad_status; then + mullvad disconnect + else + mullvad connect + fi + sleep 5 +} + +case $1 in + --status) + if mullvad_status; then + status_json=$(mullvad status --json) + endpoint=$(echo "$status_json" | jq -r '.details.endpoint | "\(.tunnel_interface) (\(.tunnel_type))"') + location=$(echo "$status_json" | jq -r '.details.location | "\(.country), \(.city) (\(.ipv4))"') + echo "{\"text\":\"\",\"class\":\"connected\",\"alt\":\"connected\", \"tooltip\": \"${endpoint}\\n${location}\"}" + else + echo "{\"text\":\"\",\"class\":\"disconnected\",\"alt\":\"disconnected\", \"tooltip\": \"VPN is not active.\"}" + fi + ;; + --toggle) + toggle_status + ;; +esac + diff --git a/config/waybar/scripts/tailscale.sh b/config/waybar/scripts/tailscale.sh new file mode 100755 index 0000000..e2e1deb --- /dev/null +++ b/config/waybar/scripts/tailscale.sh @@ -0,0 +1,39 @@ +#!/usr/bin/env bash + +STATUS_KEY="BackendState" +RUNNING="Running" + +tailscale_status () { + status="$(tailscale status --json | jq -r '.'$STATUS_KEY)" + if [ "$status" = $RUNNING ]; then + return 0 + fi + return 1 +} + +toggle_status () { + if tailscale_status; then + tailscale down + else + tailscale up + fi + sleep 5 +} + +case $1 in + --status) + if tailscale_status; then + T=${2:-"green"} + F=${3:-"red"} + + peers=$(tailscale status --json | jq -r --arg T "'$T'" --arg F "'$F'" '.Peer[] | ("" + (.DNSName | split(".")[0]) + "")' | tr '\n' '\r') + exitnode=$(tailscale status --json | jq -r '.Peer[] | select(.ExitNode == true).DNSName | split(".")[0]') + echo "{\"text\":\"${exitnode}\",\"class\":\"connected\",\"alt\":\"connected\", \"tooltip\": \"${peers}\"}" + else + echo "{\"text\":\"\",\"class\":\"stopped\",\"alt\":\"stopped\", \"tooltip\": \"Tailscale is not active.\"}" + fi + ;; + --toggle) + toggle_status + ;; +esac -- cgit