Skip to content

Commit

Permalink
feature/show-vpn-name-or-name-of-tailscale-exit-node
Browse files Browse the repository at this point in the history
  • Loading branch information
Theoreticallyhugo committed Oct 22, 2024
1 parent 80c1516 commit 29e84ad
Showing 1 changed file with 37 additions and 4 deletions.
41 changes: 37 additions & 4 deletions scripts/network_vpn.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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
;;

Expand Down

0 comments on commit 29e84ad

Please sign in to comment.