Merge pull request #589 from matt-hayden/master

Remove default from bash function
This commit is contained in:
Igor Chubin 2021-04-05 18:25:21 +02:00 committed by GitHub
commit e4d980f4ef
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -1,7 +1,31 @@
wttr()
{
# change Paris to your default location
local request="wttr.in/${1-Paris}"
[ "$(tput cols)" -lt 125 ] && request+='?n'
curl -H "Accept-Language: ${LANG%_*}" --compressed "$request"
#! /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
args+=" --data-urlencode $p "
done
curl -fGsS -H "Accept-Language: ${LANG%_*}" $args --compressed "wttr.in/${location}"
}
wttr "$@"