summaryrefslogtreecommitdiffstats
path: root/.local/bin/weath
diff options
context:
space:
mode:
authorLuke Smith <luke@lukesmith.xyz>2024-07-15 13:46:42 -0400
committerLuke Smith <luke@lukesmith.xyz>2024-07-15 13:46:42 -0400
commit628ed4dc995f3c09e33c24a01c817c18b1a268af (patch)
treee5459b11a6aa310f03deed2218d38b7ef6499b4d /.local/bin/weath
parenta9cde940c2a956f98b6a5cd8496d24fe7de58e64 (diff)
parent779ef2f5feb3221a1e29262234fafa13c4db5ab7 (diff)
downloadeibhear-628ed4dc995f3c09e33c24a01c817c18b1a268af.tar.gz
eibhear-628ed4dc995f3c09e33c24a01c817c18b1a268af.tar.zst
eibhear-628ed4dc995f3c09e33c24a01c817c18b1a268af.zip
Merge branch 'master' of github.com:LukeSmithxyz/voidrice
Diffstat (limited to '.local/bin/weath')
-rw-r--r--.local/bin/weath25
1 files changed, 25 insertions, 0 deletions
diff --git a/.local/bin/weath b/.local/bin/weath
new file mode 100644
index 0000000..a526411
--- /dev/null
+++ b/.local/bin/weath
@@ -0,0 +1,25 @@
+#!/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.
+
+report="${XDG_CACHE_HOME:-$HOME/.cache}/weatherreport"
+
+if [ "$1" = 'cp' ]; then
+ # shellcheck disable=SC2015
+ [ -z "$2" ] && sed 's/\x1b\[[^m]*m//g' "$report" | xclip -selection clipboard &&
+ notify-send "Weather forecast for '${LOCATION:-$(head -n 1 "$report" | 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" ] && less -S "$report" ||
+ data="$(curl -sfm 5 "${WTTRURL:-wttr.in}/$1")" && echo "$data" | less -S ||
+ notify-send 'Failed to get weather forecast!' 'Check your internet connection and the supplied location.'
+fi