From 54a985cb11861f3857daa7001558f015d971dc3d Mon Sep 17 00:00:00 2001 From: Dominik Ritter Date: Wed, 23 Jan 2019 01:02:42 +0100 Subject: [PATCH] Simplify code that checks if a VPN is running --- powerlevel9k.zsh-theme | 15 +++++---------- test/segments/public_ip.spec | 8 +++++--- 2 files changed, 10 insertions(+), 13 deletions(-) diff --git a/powerlevel9k.zsh-theme b/powerlevel9k.zsh-theme index 6902ed10..7437fe32 100755 --- a/powerlevel9k.zsh-theme +++ b/powerlevel9k.zsh-theme @@ -600,17 +600,12 @@ prompt_public_ip() { # Check VPN is on if VPN interface is set if [[ -n $POWERLEVEL9K_PUBLIC_IP_VPN_INTERFACE ]]; then if [[ "$OS" == "OSX" ]]; then - for vpn_iface in $(${ROOT_PREFIX}/sbin/ifconfig | grep -e "^$POWERLEVEL9K_PUBLIC_IP_VPN_INTERFACE" | cut -d":" -f1) - do - icon='VPN_ICON' - break - done + local interface="$(${ROOT_PREFIX}/sbin/ifconfig $POWERLEVEL9K_PUBLIC_IP_VPN_INTERFACE)" + # Check if interface is UP. + [[ "$interface" =~ " $FOLDER/sbin/ifconfig < mtu 1500 +${INTERFACE}: flags=4099 mtu 1500 inet 1.2.3.4 txqueuelen 1000 (Ethernet) RX packets 0 bytes 0 (0.0 B) RX errors 0 dropped 0 overruns 0 frame 0 @@ -62,7 +64,7 @@ docker0: flags=4099 mtu 1500 TX packets 0 bytes 0 (0.0 B) TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0 -tun1: flags=4099 mtu 1500 +${INTERFACE}: flags=4099 mtu 1500 inet 1.2.3.4 txqueuelen 1000 (Ethernet) RX packets 0 bytes 0 (0.0 B) RX errors 0 dropped 0 overruns 0 frame 0 @@ -337,7 +339,7 @@ function testPublicIpSegmentWithVPNTurnedOnOsx() { } # Fake ifconfig - fakeIfconfig + fakeIfconfig "tun1" assertEquals "%K{000} %F{007}(vpn) %f%F{007}1.2.3.4 " "$(prompt_public_ip left 1 false "$FOLDER")"