summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorryukamish <[email protected]>2026-06-08 12:25:29 +0530
committerryukamish <[email protected]>2026-06-08 12:25:29 +0530
commitfd322ade4d50ff0eab695648d69edc5cb2abd1b2 (patch)
tree43bbeff5d3c49bd23b1ed0a862d6e441f0bdd18e
parentfcd1c4bac7bc3c17124331ced6702d5bf72e71fa (diff)
add: vpn module for waybar
-rw-r--r--.config/waybar/config.jsonc12
-rwxr-xr-x.local/bin/waybar-vpn31
2 files changed, 37 insertions, 6 deletions
diff --git a/.config/waybar/config.jsonc b/.config/waybar/config.jsonc
index dab8552..b10f9f9 100644
--- a/.config/waybar/config.jsonc
+++ b/.config/waybar/config.jsonc
@@ -84,12 +84,12 @@
"on-click": "kitty --app-id TUI.float -e wifitui",
"on-click-right": "rfkill toggle wlan"
},
-
"custom/vpn": {
- "format": "VPN",
- "exec": "echo '{\"class\": \"connected\"}'",
- "exec-if": "test -d /proc/sys/net/ipv4/conf/proton0",
+ "format": "VPN: <span color='#aaaaaa'>{}</span>",
+ "exec": "~/.local/bin/waybar-vpn status",
+ // "exec": "echo '{\"class\": \"connected\"}'",
+ // "exec-if": "test -d /proc/sys/net/ipv4/conf/proton0",
"return-type": "json",
- "interval": 5
- },
+ "interval": 30
+ }
}
diff --git a/.local/bin/waybar-vpn b/.local/bin/waybar-vpn
new file mode 100755
index 0000000..008e743
--- /dev/null
+++ b/.local/bin/waybar-vpn
@@ -0,0 +1,31 @@
+#!/bin/sh
+
+# first user argument
+cmd="$1"
+
+case "$cmd" in
+ connect)
+ # TODO: handle root permission password input
+ if [ -n $(type "nmcli") ]; then
+ nmcli connection show --active \
+ rg -i 'wireguard'
+ fi
+ ;;
+ disconnect)
+ # `wg-quick` requires root permission to disconnect
+ # don't have the solution right now
+ ;;
+ status)
+ vpn=$(nmcli connection show --active | rg -i 'wireguard' | awk '{print $1}')
+ if [ -n "$vpn" ]; then
+ printf "{\"text\": \"$vpn\", \"class\": \"wireguard\", \"alt\": \"disconnected\" }\n"
+ else
+ printf "{\"text\": \"DC'D\", \"class\": \"wireguard\", \"alt\": \"disconnected\" }\n"
+ fi
+ ;;
+ *)
+ # print usage if not used with any of the below three commands
+ echo -e "Usage: %s {status|connect|disconnect}\n"
+ exit 1
+ ;;
+esac