diff options
| author | TheSiahxyz <164138827+TheSiahxyz@users.noreply.github.com> | 2025-08-23 13:36:06 +0900 |
|---|---|---|
| committer | TheSiahxyz <164138827+TheSiahxyz@users.noreply.github.com> | 2025-08-23 13:36:06 +0900 |
| commit | 6baef1437fcf40b1d51c5255af78ab297d361d2c (patch) | |
| tree | c3c257e026ec3fb32b787839f81d8af0c2e6c7ce /mac/.local/bin/weath | |
| parent | 07d294425a98ee5d1e22d03e2b24ae2c76e487c0 (diff) | |
updates
Diffstat (limited to 'mac/.local/bin/weath')
| -rwxr-xr-x | mac/.local/bin/weath | 46 |
1 files changed, 46 insertions, 0 deletions
diff --git a/mac/.local/bin/weath b/mac/.local/bin/weath new file mode 100755 index 0000000..d013f6f --- /dev/null +++ b/mac/.local/bin/weath @@ -0,0 +1,46 @@ +#!/bin/sh +# +# Get the weather on the terminal. You can pass an alternative location as a parameter, +# and/or use the 'cp' option to copy the forecast as plaintext to the clipboard. + +weatherreport="${XDG_CACHE_HOME:-${HOME}/.cache}/weatherreport" + +formats() { + [ "$MANPAGER" = "less -s" ] && pager=true || pager=false + [ "$pager" = "false" ] && { + export MANPAGER='less -s' + export LESS="R" + export LESS_TERMCAP_mb="$(printf '%b' '[1;31m')" + export LESS_TERMCAP_md="$(printf '%b' '[1;36m')" + export LESS_TERMCAP_me="$(printf '%b' '[0m')" + export LESS_TERMCAP_so="$(printf '%b' '[01;44;33m')" + export LESS_TERMCAP_se="$(printf '%b' '[0m')" + export LESS_TERMCAP_us="$(printf '%b' '[1;32m')" + export LESS_TERMCAP_ue="$(printf '%b' '[0m')" + export LESSOPEN="| /usr/bin/highlight -O ansi %s 2>/dev/null" + } + setsid -f "$TERMINAL" less -S "$1" >/dev/null 2>&1 + [ "$pager" = "false" ] && { + export MANPAGER="sh -c 'col -bx | bat -l man -p'" + export MANROFFOPT="-c" + } +} + +if [ "$1" = 'cp' ]; then + # shellcheck disable=SC2015 + [ -z "$2" ] && sed 's/\x1b\[[^m]*m//g' "$weatherreport" | xclip -selection clipboard && + notify-send "Weather forecast for '${LOCATION:-$(head -n 1 "$weatherreport" | cut -d' ' -f3-)}' copied to clipboard." || + { data="$(curl -sfm 5 "${WTTRURL:-wttr.in}/$2?T")" && + notify-send "ðWeather forecast for '$2' copied to clipboard." && + echo "$data" | xclip -selection clipboard || + notify-send 'ð¥¶Failed to get weather forecast!' 'Check your internet connection and the supplied location.'; } +else + [ -n "$2" ] && + notify-send "âInvalid option '$1'! The only valid option is 'cp'." && + exit 1 + + # shellcheck disable=SC2015 + [ -z "$1" ] && formats "$weatherreport" || + data="$(curl -sfm 5 "${WTTRURL:-wttr.in}/$1")" && echo "$data" | formats - || + notify-send 'âFailed to get weather forecast!' 'Check your internet connection and the supplied location.' +fi |
