#!/bin/sh # The MIT License (MIT) # # Copyright (c) 2026 pacman64 # # Permission is hereby granted, free of charge, to any person obtaining a copy # of this software and associated documentation files (the "Software"), to deal # in the Software without restriction, including without limitation the rights # to use, copy, modify, merge, publish, distribute, sublicense, and/or sell # copies of the Software, and to permit persons to whom the Software is # furnished to do so, subject to the following conditions: # # The above copyright notice and this permission notice shall be included in # all copies or substantial portions of the Software. # # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, # FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE # AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE # SOFTWARE. # tempo [options...] [places...] # # Show the current date/time, a partial calendar with the 3 months `around` # the current date, and weather forecast(s) for the places (anywhere in the # world) given, using ANSI styles to make things stand out. # # The name `tempo` comes from Italian: it means either `time` or `weather`, # depending on the context. Appropriately, this tool can tell you both. # # When not given any places to fetch weather forecasts for, this tool is a # quick way to check the current time/date and month(s). # # The options are, available both in single and double-dash versions # # -h, -help show this help message # -w, -wide wide-mode, to get a few more days on narrow terminals case "$1" in -h|--h|-help|--help) { awk '/^# +tempo /, /^$/ { gsub(/^# ?/, ""); print }' "$0" printf "Each place/argument allows the prefixes shown below.\n\n" printf "\r\n" | curl --show-error -s telnet://graph.no:79 2>&1 } | less -MKiCRS exit 0 ;; esac width="$(($(tput cols) - 2))" weather_width="${width}" case "$1" in -w|--w|-wide|--wide|-wider|--wider) weather_width="$((width * 2))" shift ;; esac [ "$1" = '--' ] && shift { # show the current date/time center-aligned printf "%*s\e[38;2;78;154;6m%s\e[0m \e[38;2;52;101;164m%s\e[0m\n\n" \ "$((width / 2 - 11))" "" "$(date +'%a %b %d %Y')" "$(date +'%H:%M')" # debian linux's `cal` can't highlight the current day if [ -e /usr/bin/ncal ]; then # `ncal` has a weird way to highlight the current day ncal -C -3 | sed -E 's/_\x08(.+)_\x08([^ ]+)/\x1b\[7m\1\2\x1b\[0m/' else cal -3 fi | awk -v n="$((width / 2 - 32))" '{ printf "%*s%s\n", n, "", $0 }' for place in "$@"; do printf "\n\e[7m%-${width}s\e[0m\n" "${place}" printf "%s~%s\r\n\r\n" "${place}" "${weather_width}" | curl --show-error -s telnet://graph.no:79 2>&1 | sed -u -E \ -e 's/ *\r?$//' \ -e '/^\[/d' \ -e 's/^ *-= *([^=]+) +=- *$/\1\n/' \ -e 's/-/\x1b[38;2;196;160;0m●\x1b[0m/g' \ -e 's/^( +)\x1b\[38;2;196;160;0m●\x1b\[0m/\1-/g' \ -e 's/\|/\x1b[38;2;52;101;164m█\x1b[0m/g' \ -e 's/=V=/-\x1b[48;2;216;150;0mV\x1b[0m-/g' \ -e 's/=/\x1b[38;2;218;218;218m█\x1b[0m/g' \ -e 's/#/\x1b[48;2;218;218;218mF\x1b[0m/g' \ -e 's/([=\^][=\^]*)/\x1b[38;2;164;164;164m\1\x1b[0m/g' \ -e 's/\*/○/g' \ -e 's/_/\x1b[48;2;216;200;0m_\x1b[0m/g' \ -e 's/([0-9][0-9]\/[0-9][0-9])/\x1b[7m\1\x1b[0m/g' | awk 1 done } | less -MKiCRS --header=11