diff options
| author | Rubén Beltrán del Río <jj@r.bdr.sh> | 2026-07-14 15:02:51 +0200 |
|---|---|---|
| committer | Rubén Beltrán del Río <jj@r.bdr.sh> | 2026-09-02 23:39:29 +0200 |
| commit | 51b27719a444764872f018a56e36ff406e892b27 (patch) | |
| tree | 426846f83d310c5d6389feeb069d30870509c54a /config/waybar/scripts/ivpn.sh | |
| parent | 34cc3551b4138cdb96e071c7c1fdd36b7d85d1cb (diff) | |
Update waybar config
Diffstat (limited to 'config/waybar/scripts/ivpn.sh')
| -rwxr-xr-x | config/waybar/scripts/ivpn.sh | 38 |
1 files changed, 38 insertions, 0 deletions
diff --git a/config/waybar/scripts/ivpn.sh b/config/waybar/scripts/ivpn.sh new file mode 100755 index 0000000..9ff88fc --- /dev/null +++ b/config/waybar/scripts/ivpn.sh @@ -0,0 +1,38 @@ +#!/usr/bin/env bash + +ivpn_status_output () { + ivpn status +} + +ivpn_connected () { + ivpn status | grep -q '^VPN.*: CONNECTED' +} + +toggle_status () { + if ivpn_connected; then + ivpn disconnect + else + ivpn connect -f + fi +} + +case $1 in + --status) + status_output="$(ivpn_status_output)" + if echo "$status_output" | grep -q '^VPN.*: CONNECTED'; then + # Line after "VPN : CONNECTED" holds server + location, + # e.g. "de.gw.ivpn.net [de3.gw.ivpn.net], Frankfurt (DE), Germany" + server_line=$(echo "$status_output" | awk '/^VPN.*CONNECTED/{getline; sub(/^[ \t]+/, ""); print}') + protocol=$(echo "$status_output" | awk -F': ' '/^[ \t]*Protocol/{print $2}') + server_ip=$(echo "$status_output" | awk -F': ' '/^[ \t]*Server IP/{print $2}') + endpoint="${server_line%%,*} (${protocol})" + location="${server_line#*, } (${server_ip})" + 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 |