diff --git a/corona.fish b/corona.fish
@@ -12,7 +12,7 @@
function __corona_select_csv -a country
echo 'đŠī¸ Country, đˇī¸ Cases, đ¤ī¸ New Cases, đī¸ Deaths, đ°ī¸ New Deaths'
- if [ (string lower "$country") = all ]
+ if test (string lower "$country") = all
cat "$HOME/.cache/corona.csv"
else
grep -Ei "^\"?($country|World)" "$HOME/.cache/corona.csv"
@@ -20,12 +20,8 @@ function __corona_select_csv -a country
end
function corona -a country -d "Track corona-virus cases from fish-shell. đˇī¸"
- switch (string lower "$country")
- case all
- set country ""
- # Figure out the host's country from his IP
- case ""
- if [ -f "$HOME/.cache/country.name" ]
+ if test -z "$country"
+ if test -f "$HOME/.cache/country.name"
set country (cat "$HOME/.cache/country.name" )
else
set country_code (curl -s https://ipinfo.io/country/)
@@ -37,12 +33,14 @@ function corona -a country -d "Track corona-virus cases from fish-shell. đˇī¸
# Update the cache if it doesn't exists or if it hasn't been modified in
# over a day
set date (date +%Y-%m-%d)
- if ! [ -f "$HOME/.cache/corona.csv" ] || \
- [ (stat -c %y "$HOME/.cache/corona.csv" | cut -d' ' -f1) = "$date" ]
+ not test -f "$HOME/.cache/corona.csv"
+ or test (stat -c %y "$HOME/.cache/corona.csv" | cut -d' ' -f1) != "$date"
+ if test "$status" -eq 0
curl -s https://corona-stats.online/\?format=json \
- | jq -r '.data[], .worldStats
- | [.country, .cases, .todayCases, .deaths, .todayDeaths]
+ | jq -r '.data + [.worldStats]
+ | .[]
+ | [.country,.cases,.todayCases,.deaths,.todayDeaths]
| @csv' \
> "$HOME/.cache/corona.csv"
end