-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathwttr
More file actions
executable file
·59 lines (53 loc) · 1.47 KB
/
wttr
File metadata and controls
executable file
·59 lines (53 loc) · 1.47 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
#!/usr/bin/env bash
# The bulk of this code is taken from <wttr.in/:bash.function>
# If you source this file, it will set WTTR_PARAMS as well as show weather.
usage() {
cat <<EOF
Usage: wttr <location> [<range>]
Locations can be:
City Name: los+angeles
Location: eiffel+tower
Airport Code: jfk
Domain Name: @stackoverflow.com
Area Code: 90210
Coordinates: -78.46,106.79
Ranges are:
0 Only current weather
1 Current weather + today's forecast
2 Current weather + today's forecast + tomorrow's forecast (default)
EOF
exit 0
}
# 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
# shellcheck disable=SC2086
# $args cannot be quoted, or the in-term formatting will break
wttr() {
if [[ "$1" == help ]]; then
usage
fi
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}?${2:+}"
}
wttr "$@"
exit 0