From 9fb4a3dc1448041610704cea0f7cda43ca52935d Mon Sep 17 00:00:00 2001 From: Michael De Roover Date: Tue, 12 May 2020 15:17:36 +0200 Subject: [PATCH] Lint and improve cv with shellcheck --- cv | 26 +++++++++++++------------- 1 file changed, 13 insertions(+), 13 deletions(-) diff --git a/cv b/cv index 8398b29..d26325e 100755 --- a/cv +++ b/cv @@ -8,13 +8,13 @@ else date=$(date +"%Y-%m-%d") ydate=$(date -d yesterday +"%Y-%m-%d") show(){ - echo -e "\033[1;36m> ${@} \033[0m" + echo -e "\\033[1;36m> ${*} \\033[0m" } fi data="$HOME/Documents/cv" -if [ ! -d $data ] +if [ ! -d "$data" ] then ex "mkdir $data" # This is just for migration. Remove afterwards. @@ -22,44 +22,44 @@ then fi # If not set by an environment variable, set country to $1. -if [ -z $country ] +if [ -z "$country" ] then country=$1 fi get(){ - if [ -f $data/$date-$country ] + if [ -f "$data/$date-$country" ] then - cat $data/$date-$country | jq -r .$1 + jq -r ".$1" < "$data/$date-$country" else - curl -sL corona.lmao.ninja/v2/$endpoint > $data/$date-$country - cat $data/$date-$country | jq -r .$1 + curl -sL corona.lmao.ninja/v2/"$endpoint" > "$data/$date-$country" + jq -r ".$1" < "$data/$date-$country" fi } yget(){ date=$ydate - get $1 + get "$1" } result(){ echo "Total: $(get cases)" echo "Active: $(get active)" echo "New: $(get todayCases)" echo "Tests: $(get tests)" - if [ -f $data/$ydate-$country ] + if [ -f "$data/$ydate-$country" ] then show "Yesterday's stats:" echo "New: $(yget todayCases)" - if [ $(get todayCases) == "0" ] + if [ "$(get todayCases)" == "0" ] then show "Seems like the cases today are not yet updated." show "The data file will be removed. Please query again later." ex "rm $data/$date-$country" - elif [ $(get todayCases) == $(yget todayCases) ] + elif [ "$(get todayCases)" == "$(yget todayCases)" ] then show "Seems like the stats are the same as yesterday." show "This could be normal but may mean that the data file is still yesterday's." show "Do you want to remove it?" - read -p "Answer (y/n): " answer + read -rp "Answer (y/n): " answer if [ "$answer" == "y" ] then ex "rm $data/$date-$country" @@ -71,7 +71,7 @@ result(){ } show "Queried at: $date" -if [ ! -z $country ] +if [ ! -z "$country" ] then if [ "$country" == "all" ] then