Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 12 additions & 2 deletions scripts/weather.sh
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,17 @@ display_weather()
temperature=$(echo $weather_information | rev | cut -d ' ' -f 1 | rev) # +31°C, -3°F, etc
unicode=$(forecast_unicode $weather_condition)

echo "$unicode ${temperature/+/}" # remove the plus sign to the temperature
# Mac Only variant should be transparent on Linux
if [[ "${temperature/+/}" == *"===="* ]]; then
temperature="error"
fi

if [[ "${temperature/+/}" == "error" ]]; then
# Propagate Error
echo "error"
else
echo "$unicode ${temperature/+/}" # remove the plus sign to the temperature
fi
}

forecast_unicode()
Expand All @@ -76,7 +86,7 @@ forecast_unicode()
main()
{
# process should be cancelled when session is killed
if timeout 1 bash -c "</dev/tcp/ipinfo.io/443" && timeout 1 bash -c "</dev/tcp/wttr.in/443"; then
if timeout 1 bash -c "</dev/tcp/ipinfo.io/443" && timeout 1 bash -c "</dev/tcp/wttr.in/443" && [[ "$(display_weather)" != "error" ]]; then
echo "$(display_weather)$(display_location)"
else
echo "Weather Unavailable"
Expand Down