From 236b082078838a9453c7b5eb63fbb9417359d479 Mon Sep 17 00:00:00 2001 From: appeasementPolitik <108810900+appeasementPolitik@users.noreply.github.com> Date: Sat, 13 May 2023 14:43:12 +0000 Subject: [PATCH 1/4] weath: Add option to get forecast from a different location --- .config/shell/aliasrc | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/.config/shell/aliasrc b/.config/shell/aliasrc index 09f9a327..501763c4 100644 --- a/.config/shell/aliasrc +++ b/.config/shell/aliasrc @@ -18,6 +18,11 @@ se() { [ -f "$HOME/.local/bin/$choice" ] && $EDITOR "$HOME/.local/bin/$choice" ;} +weath() { + [ -z "$1" ] && less -S ${XDG_CACHE_HOME:-$HOME/.cache}/weatherreport || + curl --retry 5 -sm 10 "${WTTRURL:-wttr.in}/$1" | less -S + ;} + # Verbosity and settings that you pretty much just always are going to want. alias \ cp="cp -iv" \ @@ -58,4 +63,3 @@ alias \ lf="lfub" \ magit="nvim -c MagitOnly" \ ref="shortcuts >/dev/null; source ${XDG_CONFIG_HOME:-$HOME/.config}/shell/shortcutrc ; source ${XDG_CONFIG_HOME:-$HOME/.config}/shell/zshnameddirrc" \ - weath="less -S ${XDG_CACHE_HOME:-$HOME/.cache}/weatherreport" \ From fc1cd24557438aa97d26a53a7bd9e00eb3a2d849 Mon Sep 17 00:00:00 2001 From: appeasementPolitik <108810900+appeasementPolitik@users.noreply.github.com> Date: Sun, 14 May 2023 07:59:18 +0000 Subject: [PATCH 2/4] Remove retry and make max time lower because it is interactive --- .config/shell/aliasrc | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.config/shell/aliasrc b/.config/shell/aliasrc index 501763c4..4478464d 100644 --- a/.config/shell/aliasrc +++ b/.config/shell/aliasrc @@ -20,7 +20,7 @@ se() { weath() { [ -z "$1" ] && less -S ${XDG_CACHE_HOME:-$HOME/.cache}/weatherreport || - curl --retry 5 -sm 10 "${WTTRURL:-wttr.in}/$1" | less -S + curl -sm 5 "${WTTRURL:-wttr.in}/$1" | less -S ;} # Verbosity and settings that you pretty much just always are going to want. From 7bf7b73a4ee1ce10f5b492bb07d4cee839d57550 Mon Sep 17 00:00:00 2001 From: appeasementPolitik <108810900+appeasementPolitik@users.noreply.github.com> Date: Thu, 24 Aug 2023 14:20:23 +0000 Subject: [PATCH 3/4] Give weath 'cp' option to copy forecast as plain text for sharing --- .config/shell/aliasrc | 22 ++++++++++++++++++---- 1 file changed, 18 insertions(+), 4 deletions(-) diff --git a/.config/shell/aliasrc b/.config/shell/aliasrc index 4478464d..93bbbe9b 100644 --- a/.config/shell/aliasrc +++ b/.config/shell/aliasrc @@ -16,12 +16,26 @@ done; unset command se() { choice="$(find ~/.local/bin -mindepth 1 -printf '%P\n' | fzf)" [ -f "$HOME/.local/bin/$choice" ] && $EDITOR "$HOME/.local/bin/$choice" - ;} + } weath() { - [ -z "$1" ] && less -S ${XDG_CACHE_HOME:-$HOME/.cache}/weatherreport || - curl -sm 5 "${WTTRURL:-wttr.in}/$1" | less -S - ;} + if [ "$1" = 'cp' ]; then + [ -z "$2" ] && sed 's/\x1b\[[^m]*m//g' "${XDG_CACHE_HOME:-$HOME/.cache}/weatherreport" | xclip -selection clipboard && + notify-send "Weather forecast for '$LOCATION' 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 if the location is correct.'; } + else + [ -n "$2" ] && + notify-send "Invalid option '$1'! The only valid option is 'cp'." && + return 1 + + [ -z "$1" ] && less -S "${XDG_CACHE_HOME:-$HOME/.cache}/weatherreport" || + data="$(curl -sfm 5 "${WTTRURL:-wttr.in}/$1")" && echo "$data" | less -S || + notify-send 'Failed to get weather forecast!' 'Check your internet connection and if the location is correct.' + fi + } # Verbosity and settings that you pretty much just always are going to want. alias \ From ba070c3d79bcff466412da06fc46d901b6bfbcd7 Mon Sep 17 00:00:00 2001 From: appeasementPolitik <108810900+appeasementPolitik@users.noreply.github.com> Date: Sat, 25 Nov 2023 09:46:48 +0000 Subject: [PATCH 4/4] Make weath a separate script --- .config/shell/aliasrc | 19 ------------------- .local/bin/weath | 25 +++++++++++++++++++++++++ 2 files changed, 25 insertions(+), 19 deletions(-) create mode 100644 .local/bin/weath diff --git a/.config/shell/aliasrc b/.config/shell/aliasrc index 93bbbe9b..07683372 100644 --- a/.config/shell/aliasrc +++ b/.config/shell/aliasrc @@ -18,25 +18,6 @@ se() { [ -f "$HOME/.local/bin/$choice" ] && $EDITOR "$HOME/.local/bin/$choice" } -weath() { - if [ "$1" = 'cp' ]; then - [ -z "$2" ] && sed 's/\x1b\[[^m]*m//g' "${XDG_CACHE_HOME:-$HOME/.cache}/weatherreport" | xclip -selection clipboard && - notify-send "Weather forecast for '$LOCATION' 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 if the location is correct.'; } - else - [ -n "$2" ] && - notify-send "Invalid option '$1'! The only valid option is 'cp'." && - return 1 - - [ -z "$1" ] && less -S "${XDG_CACHE_HOME:-$HOME/.cache}/weatherreport" || - data="$(curl -sfm 5 "${WTTRURL:-wttr.in}/$1")" && echo "$data" | less -S || - notify-send 'Failed to get weather forecast!' 'Check your internet connection and if the location is correct.' - fi - } - # Verbosity and settings that you pretty much just always are going to want. alias \ cp="cp -iv" \ diff --git a/.local/bin/weath b/.local/bin/weath new file mode 100644 index 00000000..a5264110 --- /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