Skip to content

Instantly share code, notes, and snippets.

@ali-aka-ahmed
Last active April 14, 2022 21:38
Show Gist options
  • Save ali-aka-ahmed/31fd318fdf8924facd71660afe965b5f to your computer and use it in GitHub Desktop.
Save ali-aka-ahmed/31fd318fdf8924facd71660afe965b5f to your computer and use it in GitHub Desktop.
wttr.in shell function for .zshrc/.bashrc
weather() {
# Handle our variables
# If no arg is given, default to San Francisco
local request curlArgs
curlArgs="-H \"Accept-Language: ${LANG%_*}\" --compressed -m 10"
case "${1}" in
(-h|--help) request="wttr.in/:help" ;;
(*) request="wttr.in/${*:-SanFrancisco}?u" ;;
esac
# Finally, make the request
curl "${curlArgs}" "${request}" 2>/dev/null \
|| printf '%s\n' "[ERROR] weather: Could not connect to weather service."
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment