From bde4337992e01738e72ef589c321299193580838 Mon Sep 17 00:00:00 2001 From: Dominik Ritter Date: Wed, 23 Jan 2019 18:56:07 +0100 Subject: [PATCH] Match VPN Interface fuzzy --- powerlevel9k.zsh-theme | 22 +++++++++++++++++++--- test/segments/public_ip.spec | 31 ++++++++++++++++++++++++++++++- 2 files changed, 49 insertions(+), 4 deletions(-) diff --git a/powerlevel9k.zsh-theme b/powerlevel9k.zsh-theme index 7437fe32..081562b5 100755 --- a/powerlevel9k.zsh-theme +++ b/powerlevel9k.zsh-theme @@ -600,9 +600,25 @@ prompt_public_ip() { # Check VPN is on if VPN interface is set if [[ -n $POWERLEVEL9K_PUBLIC_IP_VPN_INTERFACE ]]; then if [[ "$OS" == "OSX" ]]; then - local interface="$(${ROOT_PREFIX}/sbin/ifconfig $POWERLEVEL9K_PUBLIC_IP_VPN_INTERFACE)" - # Check if interface is UP. - [[ "$interface" =~ " $FOLDER/sbin/ifconfig < mtu 1500 inet 1.2.3.4 txqueuelen 1000 (Ethernet) @@ -55,6 +60,7 @@ INNER exit 0 fi +if [[ "\$#" == "0" ]]; then cat < mtu 1500 inet 172.17.0.1 netmask 255.255.0.0 broadcast 172.17.255.255 @@ -81,6 +87,7 @@ lo: flags=73 mtu 65536 TX packets 5136 bytes 328651 (320.9 KiB) TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0 INNER +fi EOF chmod +x $FOLDER/sbin/ifconfig } @@ -346,4 +353,26 @@ function testPublicIpSegmentWithVPNTurnedOnOsx() { unfunction stat } +function testPublicIpSegmentWithVPNTurnedOnAndFuzzyMatchingOnOsx() { + typeset -F now + now=$(date +%s) + + local OS='OSX' + + echo "1.2.3.4" > $POWERLEVEL9K_PUBLIC_IP_FILE + local POWERLEVEL9K_PUBLIC_IP_VPN_INTERFACE="tun" + + # Fake stat call + function stat() { + echo $now + } + + # Fake ifconfig + fakeIfconfig "tun3" + + assertEquals "%K{000} %F{007}(vpn) %f%F{007}1.2.3.4 " "$(prompt_public_ip left 1 false "$FOLDER")" + + unfunction stat +} + source shunit2/shunit2 \ No newline at end of file