Add tmux-vpn-ip helper (parses ifconfig for utun* on macOS, falls back to tun/wg/ppp on Linux) and a tmux-net wrapper that conditionally emits "⌂ <local> / ⇡ <vpn>" when a VPN tunnel is up, or just "<local>" when it's not. status-right now calls tmux-net.
25 lines
586 B
Bash
Executable File
25 lines
586 B
Bash
Executable File
#!/bin/bash
|
|
#
|
|
# Print the IPv4 of the first active VPN tunnel interface, if any.
|
|
# Empty output when no VPN is up.
|
|
#
|
|
# macOS: utun* Linux: tun*, wg*, ppp*
|
|
|
|
set -u
|
|
|
|
case "$(uname -s)" in
|
|
Darwin)
|
|
ifconfig 2>/dev/null | awk '
|
|
/^utun[0-9]+:/ { iface=$1; sub(":", "", iface); next }
|
|
/^[a-z]+[0-9]*:/ { iface="" }
|
|
iface != "" && $1 == "inet" { print $2; exit }
|
|
'
|
|
;;
|
|
Linux)
|
|
if command -v ip >/dev/null 2>&1; then
|
|
ip -4 -o addr show 2>/dev/null \
|
|
| awk '$2 ~ /^(tun|wg|ppp)[0-9]+/ { sub("/.*","",$4); print $4; exit }'
|
|
fi
|
|
;;
|
|
esac
|