From 01a7b4118f4c5000dcb89a445f1bb28262f09f79 Mon Sep 17 00:00:00 2001 From: Tony Blyler Date: Mon, 11 Jul 2022 10:58:10 -0400 Subject: [PATCH] Do not allow the weather zsh status code to take longer than 5s to complete --- chezmoi/dot_zshrc.d/executable_weather.zsh | 17 ++++++++++++++--- 1 file changed, 14 insertions(+), 3 deletions(-) diff --git a/chezmoi/dot_zshrc.d/executable_weather.zsh b/chezmoi/dot_zshrc.d/executable_weather.zsh index a894952..185b832 100644 --- a/chezmoi/dot_zshrc.d/executable_weather.zsh +++ b/chezmoi/dot_zshrc.d/executable_weather.zsh @@ -3,6 +3,8 @@ zmodload zsh/datetime zmodload -F zsh/stat b:zstat +readonly WEATHER_CURL_TIMEOUT="${WEATHER_CURL_TIMEOUT:-5}" + function weather_check_requirements() { [ -r "$(_weather_api_key_path)" ] && \ [ -r "$(_weather_home_location_key_path)" ] && \ @@ -149,7 +151,10 @@ function _weather_current_conditions() { TEMP_OUTPUT="$(mktemp)" trap 'rm -f "${TEMP_OUTPUT}"' EXIT - curl -LSsf --get -X GET \ + curl -LSsf \ + --max-time "${WEATHER_CURL_TIMEOUT}" \ + --get \ + -X GET \ --data-urlencode "apikey=${WEATHER_API_KEY}" \ --data-urlencode "language=en-us" \ --data-urlencode "details=true" \ @@ -184,7 +189,10 @@ function _weather_12_hour_forecast() { TEMP_OUTPUT="$(mktemp)" trap 'rm -f "${TEMP_OUTPUT}"' EXIT - curl -LSsf --get -X GET \ + curl -LSsf \ + --max-time "${WEATHER_CURL_TIMEOUT}" \ + --get \ + -X GET \ --data-urlencode "apikey=${WEATHER_API_KEY}" \ --data-urlencode "language=en-us" \ --data-urlencode "details=true" \ @@ -219,7 +227,10 @@ function _weather_5_day_daily_forecast() { TEMP_OUTPUT="$(mktemp)" trap 'rm -f "${TEMP_OUTPUT}"' EXIT - curl -LSsf --get -X GET \ + curl -LSsf \ + --max-time "${WEATHER_CURL_TIMEOUT}" \ + --get \ + -X GET \ --data-urlencode "apikey=${WEATHER_API_KEY}" \ --data-urlencode "language=en-us" \ --data-urlencode "details=true" \