From 0dc4420eccf84062659cf819b087215901d8d7da Mon Sep 17 00:00:00 2001 From: SqrtMinusOne Date: Thu, 28 Oct 2021 15:48:50 +0300 Subject: [PATCH] fix(ipstack-vpn): do not err on wrong JSON from API --- Desktop.org | 6 +++++- bin/polybar/ipstack-vpn.sh | 6 +++++- 2 files changed, 10 insertions(+), 2 deletions(-) diff --git a/Desktop.org b/Desktop.org index c39ea3c..5da054f 100644 --- a/Desktop.org +++ b/Desktop.org @@ -993,9 +993,13 @@ if [[ -z $ip || $ip == *"timed out"* ]]; then fi ip_info=$(curl -s http://api.ipstack.com/${ip}?access_key=${API_KEY}) # emoji=$(echo $ip_info | jq -r '.location.country_flag_emoji') -code=$(echo $ip_info | jq -r '.country_code') +code=$(echo $ip_info | jq -r '.country_code' 2> /dev/null) vpn=$(pgrep -a openvpn$ | head -n 1 | awk '{print $NF }' | cut -d '.' -f 1) +if [[ -z $code ]]; then + code="??" +fi + if [ -n "$vpn" ]; then echo "%{u<>}%{+u}  $code %{u-}" else diff --git a/bin/polybar/ipstack-vpn.sh b/bin/polybar/ipstack-vpn.sh index 252bc0a..f545d08 100755 --- a/bin/polybar/ipstack-vpn.sh +++ b/bin/polybar/ipstack-vpn.sh @@ -9,9 +9,13 @@ if [[ -z $ip || $ip == *"timed out"* ]]; then fi ip_info=$(curl -s http://api.ipstack.com/${ip}?access_key=${API_KEY}) # emoji=$(echo $ip_info | jq -r '.location.country_flag_emoji') -code=$(echo $ip_info | jq -r '.country_code') +code=$(echo $ip_info | jq -r '.country_code' 2> /dev/null) vpn=$(pgrep -a openvpn$ | head -n 1 | awk '{print $NF }' | cut -d '.' -f 1) +if [[ -z $code ]]; then + code="??" +fi + if [ -n "$vpn" ]; then echo "%{u#82aaff}%{+u}  $code %{u-}" else