diff --git a/.local/bin/tmux-net b/.local/bin/tmux-net new file mode 100755 index 00000000..906f88f4 --- /dev/null +++ b/.local/bin/tmux-net @@ -0,0 +1,17 @@ +#!/bin/bash +# +# Emit the tmux status-bar network segment. +# No VPN: "" +# VPN up: " (local) / (vpn)" +# + +set -u + +local_ip=$("$HOME/.local/bin/tmux-ip" 2>/dev/null || true) +vpn_ip=$("$HOME/.local/bin/tmux-vpn-ip" 2>/dev/null || true) + +if [ -n "${vpn_ip:-}" ]; then + printf '\xe2\x8c\x82 %s / \xe2\x87\xa1 %s\n' "${local_ip:-}" "$vpn_ip" +else + printf '%s\n' "${local_ip:-}" +fi diff --git a/.local/bin/tmux-vpn-ip b/.local/bin/tmux-vpn-ip new file mode 100755 index 00000000..44304a06 --- /dev/null +++ b/.local/bin/tmux-vpn-ip @@ -0,0 +1,24 @@ +#!/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 diff --git a/.tmux.conf b/.tmux.conf index 072917a6..e4e9fb3c 100644 --- a/.tmux.conf +++ b/.tmux.conf @@ -79,7 +79,7 @@ set -g pane-border-style fg=colour245 set -g pane-active-border-style fg=colour39 set -g message-style fg=colour16,bg=colour221,bold set -g status-left '#[fg=colour235,bg=colour252,bold] ❐ #S #[fg=colour252,bg=colour238,nobold]❯#[fg=colour245,bg=colour238,bold] #(whoami) ' -set -g status-right '#[bold][#[nobold,fg=colour229]#H#[fg=default] / #[fg=colour229]#(~/.local/bin/tmux-ip)#[fg=default,bold]]#[nobold,fg=colour255] %H:%M %d-%b-%Y ' +set -g status-right '#[bold][#[nobold,fg=colour229]#H#[fg=default] / #[fg=colour229]#(~/.local/bin/tmux-net)#[fg=default,bold]]#[nobold,fg=colour255] %H:%M %d-%b-%Y ' set -g window-status-format '#[fg=colour235,bg=colour252,nobold] #(~/.local/bin/tmux-window-icon #{window_index}) #(pwd="#{pane_current_path}"; echo ${pwd####*/}) #W ' set -g window-status-current-format '#[fg=colour234,bg=colour39,bold] [#[fg=colour232,bold]#{?window_zoomed_flag,#[fg=colour228],} #(~/.local/bin/tmux-window-icon #{window_index}) #(pwd="#{pane_current_path}"; echo ${pwd####*/}) #W #[fg=colour234,bold]] ' set-option -g status-interval 60