diff options
| author | Ruben Beltran del Rio <git@r.bdr.sh> | 2025-04-08 13:15:42 +0200 |
|---|---|---|
| committer | Ruben Beltran del Rio <git@r.bdr.sh> | 2025-04-08 13:15:42 +0200 |
| commit | 72af419c43ec493d4cea7bb650897b358e5f3e4a (patch) | |
| tree | e33d8152cac444f096e2f9ad496a2a398c3293d3 /config/waybar/scripts/mullvad.sh | |
| parent | b655f1dc31df1ee1c33495b3aa57e4ba4a77caa2 (diff) | |
Make bar glyphier
Diffstat (limited to 'config/waybar/scripts/mullvad.sh')
| -rwxr-xr-x | config/waybar/scripts/mullvad.sh | 38 |
1 files changed, 38 insertions, 0 deletions
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 + |