From 28a139b5c7cb4f4157980ceb2025a00f9ab44672 Mon Sep 17 00:00:00 2001 From: Thomas Dehaeze Date: Mon, 17 Feb 2020 22:11:08 +0100 Subject: [PATCH] Improve efficiency of Nordvpn polybar status --- dotfiles/polybar.org | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/dotfiles/polybar.org b/dotfiles/polybar.org index b800a83..7008acc 100644 --- a/dotfiles/polybar.org +++ b/dotfiles/polybar.org @@ -491,11 +491,9 @@ :header-args+: :shebang "#!/usr/bin/env bash" :END: #+BEGIN_SRC bash - vpnstatus=`nordvpn status`; + tmpfile="/tmp/vpnstatus"; - if [[ ${vpnstatus} == *"Connected"* ]]; then - # country=`nordvpn status | sed '/Country/!d ; s/Country: //'` - # echo "%{F#859900}%{F-} $country"; + if [ -f $tmpfile ] && grep -q "on" $tmpfile; then echo "%{F#859900}%{F-}"; else echo ""; @@ -509,12 +507,14 @@ :header-args+: :shebang "#!/usr/bin/env bash" :END: #+BEGIN_SRC bash - if [[ $(nordvpn status) == *"Connected"* ]]; then - nordvpn disconnect && dunstify --replace=23198 "VPN" "Disconnected"; + tmpfile="/tmp/vpnstatus"; + + if [ -f $tmpfile ] && grep -q "on" $tmpfile; then + nordvpn disconnect && dunstify --replace=23198 "VPN" "Disconnected" && echo "off" > $tmpfile; else country=`cat ~/bin/nordvpn_countries.txt | sed 's/\s*\t\s*/ /g ; s/\s/\n/g ; s/_/ /g ; /^[a-zA-Z]/!d ; s/\(.*\)/\L\1/' | rofi -i -dmenu | sed 's/\s/_/g'`; dunstify --replace=23198 "VPN" "Connecting to $country..."; - nordvpn connect $country && dunstify --replace=23198 "VPN" "Connected to $country"; + nordvpn connect $country && dunstify --replace=23198 "VPN" "Connected to $country" && echo "on" > $tmpfile; fi #+END_SRC