wttr.in/share/bash-function.txt

32 lines
871 B
Text
Raw Normal View History

#! /usr/bin/env bash
# If you source this file, it will set WTTR_PARAMS as well as show weather.
# WTTR_PARAMS is space-separated URL parameters, many of which are single characters that can be
# lumped together. For example, "F q m" behaves the same as "Fqm".
if [[ -z "$WTTR_PARAMS" ]]; then
# Form localized URL parameters for curl
if [[ -t 1 ]] && [[ "$(tput cols)" -lt 125 ]]; then
WTTR_PARAMS+='n'
fi 2> /dev/null
for _token in $( locale LC_MEASUREMENT ); do
case $_token in
1) WTTR_PARAMS+='m' ;;
2) WTTR_PARAMS+='u' ;;
esac
done 2> /dev/null
unset _token
export WTTR_PARAMS
fi
wttr() {
local location="${1// /+}"
command shift
local args=""
for p in $WTTR_PARAMS "$@"; do
2021-03-14 23:04:23 +00:00
args+=" --data-urlencode $p "
done
curl -fGsS -H "Accept-Language: ${LANG%_*}" $args --compressed "wttr.in/${location}"
2017-03-06 07:13:46 +00:00
}
wttr "$@"