From 747b94b1b6b8450375a2b1619d8a5c7336be1852 Mon Sep 17 00:00:00 2001 From: Dominik Ritter Date: Wed, 23 Jan 2019 19:10:46 +0100 Subject: [PATCH] Match VPN interface fuzzy on Linux --- powerlevel9k.zsh-theme | 11 +++++++++-- test/segments/public_ip.spec | 9 +++++++++ 2 files changed, 18 insertions(+), 2 deletions(-) diff --git a/powerlevel9k.zsh-theme b/powerlevel9k.zsh-theme index 081562b5..3db36050 100755 --- a/powerlevel9k.zsh-theme +++ b/powerlevel9k.zsh-theme @@ -620,8 +620,15 @@ prompt_public_ip() { fi done else - local interface=$(${ROOT_PREFIX}/sbin/ip -brief -4 a show "${POWERLEVEL9K_PUBLIC_IP_VPN_INTERFACE}") - [[ -n "$interface" ]] && icon='VPN_ICON' + local -a interfaces + interfaces=( "${(f)$(${ROOT_PREFIX}/sbin/ip -brief -4 a show)}" ) + local pattern="^${POWERLEVEL9K_PUBLIC_IP_VPN_INTERFACE}[ ]+UP[ ]+" + for interface in "${(@)interfaces}"; do + if [[ "$interface" =~ $pattern ]]; then + icon='VPN_ICON' + break + fi + done fi fi $1_prompt_segment "$0" "$2" "$DEFAULT_COLOR" "$DEFAULT_COLOR_INVERTED" "${public_ip}" "$icon" diff --git a/test/segments/public_ip.spec b/test/segments/public_ip.spec index 39b0243c..5ae62321 100755 --- a/test/segments/public_ip.spec +++ b/test/segments/public_ip.spec @@ -113,6 +113,15 @@ function fakeIp() { INNER fi + if [[ "\$*" =~ '-brief.*show' ]]; then + cat < mtu 1500 qdisc pfifo_fast state UP group default qlen 1000