From 12f9e9754f286923c828d6f0af47ece5c80823d5 Mon Sep 17 00:00:00 2001 From: Theoreticallyhugo Date: Mon, 19 Aug 2024 14:58:52 +0200 Subject: [PATCH 1/3] feature/show-vpn-name-or-name-of-tailscale-exit-node --- scripts/network_vpn.sh | 41 +++++++++++++++++++++++++++++++++++++---- 1 file changed, 37 insertions(+), 4 deletions(-) diff --git a/scripts/network_vpn.sh b/scripts/network_vpn.sh index 72229a6d..50379bf6 100755 --- a/scripts/network_vpn.sh +++ b/scripts/network_vpn.sh @@ -17,14 +17,47 @@ vpn_function() { echo "NO VPN" fi ;; - + Darwin) - vpn=$(scutil --nc list | grep Connected) - if [ -z $vpn ]; then + verbose=$(get_tmux_option "@dracula-network-vpn-verbose" false) + + vpn="$(scutil --nc list | sed "s/\*//g" | grep Connected)" + + is_not_tailscale=$(echo "$vpn" | grep -v Tailscale) + + which -s tailscale > /dev/null + tailscale_installed=$? + + if [ -z "$vpn" ]; then echo "" + + elif [ $tailscale_installed ] && [ -z "$is_not_tailscale" ]; then + # if tailscale is installed and no other vpn is connected. this is because tailscale will + # always show as connected for some reason. + # + # https://www.reddit.com/r/Tailscale/comments/18dirro/is_there_a_way_i_can_tell_which_exit_node_i_am/ + node=$(tailscale status --peers --json | jq '.ExitNodeStatus') + if [[ -z $node ]] || [[ "$node" == 'null' ]]; then + # no tailscale exit node, no output, since trafic isnt actually rerouted + echo "" + else + exitnode=$(tailscale status | grep "; exit node" | cut -w -f 2) + + if $verbose; then + echo "󰌘 $exitnode" + else + echo "Tailscale" + fi + fi + else - echo "VPN" + if $verbose; then + vpn_name=$(echo $is_not_tailscale | sed "s/.*\"\(.*\)\".*/\1/g") + echo "󰌘 $vpn_name" + else + echo "VPN" + fi fi ;; From 2919c24d5e6eae63b76f4c220ac7886d6ad9f866 Mon Sep 17 00:00:00 2001 From: Theoreticallyhugo Date: Thu, 24 Oct 2024 18:29:14 +0200 Subject: [PATCH 2/3] added tailscale support for linux --- scripts/network_vpn.sh | 41 ++++++++++++++++++++++++++++++++++++----- 1 file changed, 36 insertions(+), 5 deletions(-) diff --git a/scripts/network_vpn.sh b/scripts/network_vpn.sh index 50379bf6..56ca63bd 100755 --- a/scripts/network_vpn.sh +++ b/scripts/network_vpn.sh @@ -5,16 +5,43 @@ export LC_ALL=en_US.UTF-8 current_dir="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)" source $current_dir/utils.sh + + vpn_function() { case $(uname -s) in Linux) + + verbose=$(get_tmux_option "@dracula-network-vpn-verbose" false) + #Show IP of tun0 if connected vpn=$(ip -o -4 addr show dev tun0 | awk '{print $4}' | cut -d/ -f1) + which -s tailscale > /dev/null + tailscale_installed=$? + if [[ $vpn =~ ^([0-9]{1,3}\.){3}[0-9]{1,3}$ ]]; then echo $vpn + elif [ $tailscale_installed ]; then + # if tailscale is installed + # + # https://www.reddit.com/r/Tailscale/comments/18dirro/is_there_a_way_i_can_tell_which_exit_node_i_am/ + node=$(tailscale status --peers --json | jq '.ExitNodeStatus') + if [[ -z $node ]] || [[ "$node" == 'null' ]]; then + # no tailscale exit node, no output, since trafic isnt actually rerouted + echo "" + else + exitnode=$(tailscale status | grep "; exit node" | awk '{print $2}') + + if $verbose; then + vpn_label=$(get_tmux_option "@dracula-network-vpn-label" "󰌘 ") + echo "$vpn_label$exitnode" + else + vpn_label=$(get_tmux_option "@dracula-network-vpn-label" "Tailscale") + echo "$vpn_label" + fi + fi else - echo "NO VPN" + echo "" fi ;; @@ -45,18 +72,22 @@ vpn_function() { exitnode=$(tailscale status | grep "; exit node" | cut -w -f 2) if $verbose; then - echo "󰌘 $exitnode" + vpn_label=$(get_tmux_option "@dracula-network-vpn-label" "󰌘 ") + echo "$vpn_label$exitnode" else - echo "Tailscale" + vpn_label=$(get_tmux_option "@dracula-network-vpn-label" "Tailscale") + echo "$vpn_label" fi fi else if $verbose; then vpn_name=$(echo $is_not_tailscale | sed "s/.*\"\(.*\)\".*/\1/g") - echo "󰌘 $vpn_name" + vpn_label=$(get_tmux_option "@dracula-network-vpn-label" "󰌘 ") + echo "$vpn_label$vpn_name" else - echo "VPN" + vpn_label=$(get_tmux_option "@dracula-network-vpn-label" "VPN") + echo "$vpn_label" fi fi ;; From 7f90cd1e1b7003de357c4225d952dacef5fc1a8b Mon Sep 17 00:00:00 2001 From: Theoreticallyhugo Date: Mon, 24 Feb 2025 23:52:51 +0100 Subject: [PATCH 3/3] remove jq as dependency. fix bug where exitnode icon is displayed when tailscale is down. --- scripts/network_vpn.sh | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/scripts/network_vpn.sh b/scripts/network_vpn.sh index 56ca63bd..4ef3f350 100755 --- a/scripts/network_vpn.sh +++ b/scripts/network_vpn.sh @@ -25,7 +25,7 @@ vpn_function() { # if tailscale is installed # # https://www.reddit.com/r/Tailscale/comments/18dirro/is_there_a_way_i_can_tell_which_exit_node_i_am/ - node=$(tailscale status --peers --json | jq '.ExitNodeStatus') + node=$(tailscale status | grep "; exit node") if [[ -z $node ]] || [[ "$node" == 'null' ]]; then # no tailscale exit node, no output, since trafic isnt actually rerouted echo "" @@ -64,7 +64,7 @@ vpn_function() { # always show as connected for some reason. # # https://www.reddit.com/r/Tailscale/comments/18dirro/is_there_a_way_i_can_tell_which_exit_node_i_am/ - node=$(tailscale status --peers --json | jq '.ExitNodeStatus') + node=$(tailscale status | grep "; exit node") if [[ -z $node ]] || [[ "$node" == 'null' ]]; then # no tailscale exit node, no output, since trafic isnt actually rerouted echo ""