Improve efficiency of Nordvpn polybar status

This commit is contained in:
Thomas Dehaeze 2020-02-17 22:11:08 +01:00
parent c5a22c5585
commit 28a139b5c7

View File

@ -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