mirror of
https://github.com/chubin/wttr.in
synced 2025-01-12 03:58:45 +00:00
Recommended bash function doesn't force an arbitrary default
This commit is contained in:
parent
35cb1eddb5
commit
42635d9c6f
1 changed files with 30 additions and 6 deletions
|
@ -1,7 +1,31 @@
|
||||||
wttr()
|
#! /usr/bin/env bash
|
||||||
{
|
# If you source this file, it will set WTTR_PARAMS as well as show weather.
|
||||||
# change Paris to your default location
|
|
||||||
local request="wttr.in/${1-Paris}"
|
# WTTR_PARAMS is space-separated URL parameters, many of which are single characters that can be
|
||||||
[ "$(tput cols)" -lt 125 ] && request+='?n'
|
# lumped together. For example, "F q m" behaves the same as "Fqm".
|
||||||
curl -H "Accept-Language: ${LANG%_*}" --compressed "$request"
|
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
|
||||||
|
args+=" --data-urlencode '$p' "
|
||||||
|
done
|
||||||
|
curl -fGsS -H "Accept-Language: ${LANG%_*}" $args --compressed "wttr.in/${location}"
|
||||||
}
|
}
|
||||||
|
|
||||||
|
wttr "$@"
|
||||||
|
|
Loading…
Reference in a new issue