diff --git a/weather b/weather index 322e345..d4a8b0a 100755 --- a/weather +++ b/weather @@ -11,6 +11,7 @@ options: -a, --apikey set the api key to use to KEY -l, --location print the location being used -p, --pretty enables nerdfont symbols + -d, --desc prints the conditions text as well -z, --zipcode returns the weather for ZIPCODE -s, --search returns the weather for QUERY -u, --units sets the temperature units @@ -47,10 +48,16 @@ print_weather() { # check to see if it is expired check_expiration - # trimming state + # checking if description enabled + if [[ "$DESCRIPTION" = true ]] ; then + DESC=$(echo "$CONDITIONS" | awk '{for(i=1;i<=NF;i++){ $i=toupper(substr($i,1,1)) substr($i,2) }}1') + DESC=$(printf '%s ' "$DESC") + fi + if [[ "$PRETTY" = true ]] ; then # print with NF icons icon=$(get_icon "$WEATHER_ICON") + humidity_icon=$(echo -e '\ue373') # checking units if [[ "$UNIT" == "C" ]] ; then @@ -58,13 +65,19 @@ print_weather() { else temp_icon=$(echo -e '\ufa04') fi - # printing - printf '%s %.1f%s %d\ue373 in %s\n' $icon $TEMPERATURE "$temp_icon" "$HUMIDITY" "$CITY" else # default printing - printf '%.1f*%s %d%% RH in %s\n' $TEMPERATURE $UNIT $HUMIDITY "$CITY" + humidity_icon="% RH" + if [[ "$UNIT" == "C" ]] ; then + temp_icon="*C" + else + temp_icon="*F" + fi fi + # printing + printf '%s%s %.1f%s %d%s in %s\n' "$DESC" "$icon" $TEMPERATURE "$temp_icon" $HUMIDITY "$humidity_icon" "$CITY" + # save before exiting save_info } @@ -192,6 +205,7 @@ get_weather() { WEATHER=$(curl --silent -fL "$WEATHER_URL") + CONDITIONS=$(echo $WEATHER | gojq -r '.weather[0].description') TEMPERATURE=$(echo $WEATHER | gojq -r '.main.temp') HUMIDITY=$(echo $WEATHER | gojq -r '.main.humidity') WEATHER_ICON=$(echo $WEATHER | gojq -r '.weather[0].icon') @@ -218,17 +232,18 @@ update_key() { save_info() { # saves set env vars to file - printf '%s\n' \ -"API_KEY=$API_KEY" \ -"PARSER=$PARSER" \ -"LAT=$LAT" \ -"LON=$LON" \ -"CITY=$CITY" \ -"TEMPERATURE=$TEMPERATURE" \ -"HUMIDITY=$HUMIDITY" \ -"UNIT=$UNIT" \ -"WEATHER_ICON=$WEATHER_ICON" \ -"EXPIRATION=$EXPIRATION" > "$WEATHER_FILE" + printf '%s="%s"\n' \ +"API_KEY" "$API_KEY" \ +"PARSER" "$PARSER" \ +"LAT" "$LAT" \ +"LON" "$LON" \ +"CITY" "$CITY" \ +"TEMPERATURE" "$TEMPERATURE" \ +"HUMIDITY" "$HUMIDITY" \ +"UNIT" "$UNIT" \ +"WEATHER_ICON" "$WEATHER_ICON" \ +"CONDITIONS" "$CONDITIONS" \ +"EXPIRATION" "$EXPIRATION" > "$WEATHER_FILE" } load_info() { @@ -335,6 +350,7 @@ for arg in "$@"; do '--search') set -- "$@" "-s" ;; '--units') set -- "$@" "-u" ;; '--pretty') set -- "$@" "-p" ;; + '--pretty') set -- "$@" "-p" ;; '--icon_test') set -- "$@" "-i" ;; '--help') set -- "$@" "-h" ;; *) set -- "$@" "$arg" ;; @@ -344,7 +360,7 @@ done # loading the info load_info -while getopts "chpliz:s:u:a:" opt; do +while getopts "chpldiz:s:u:a:" opt; do case "$opt" in 'a' ) API_KEY="$OPTARG" @@ -366,6 +382,9 @@ while getopts "chpliz:s:u:a:" opt; do 'p' ) PRETTY=true ;; + 'd' ) + DESCRIPTION=true + ;; 'i' ) icon_test exit 0