From eb4c6990ecd6b19753077ec29e2d66ec91ce19b9 Mon Sep 17 00:00:00 2001 From: Michael Housh Date: Wed, 1 Oct 2025 22:12:45 -0400 Subject: [PATCH] feat: Renames get-weather script to just weather. --- env/.config/hypr/windows.conf | 5 ++ env/.local/scripts/get-weather | 14 ---- env/.local/scripts/weather | 78 +++++++++++++++++++ env/.local/share/applications/weather.desktop | 2 +- 4 files changed, 84 insertions(+), 15 deletions(-) delete mode 100755 env/.local/scripts/get-weather create mode 100755 env/.local/scripts/weather mode change 100644 => 100755 env/.local/share/applications/weather.desktop diff --git a/env/.config/hypr/windows.conf b/env/.config/hypr/windows.conf index 3e51418..9290a62 100644 --- a/env/.config/hypr/windows.conf +++ b/env/.config/hypr/windows.conf @@ -10,6 +10,11 @@ windowrule = float, tag:floating-window windowrule = center, tag:floating-window windowrule = size 800 600, tag:floating-window +# Weather tui +windowrule = float, class:^(com.ghostty.weather)$ +windowrule = center, class:^(com.ghostty.weather)$ +windowrule = size 90% 80%, class:^(com.ghostty.weather)$ + # Force windows to be a floating window windowrule = tag +floating-window, class:^(blueberry.py|org.gnome.Nautilus|com.ghostty.float)$ diff --git a/env/.local/scripts/get-weather b/env/.local/scripts/get-weather deleted file mode 100755 index 85d6dac..0000000 --- a/env/.local/scripts/get-weather +++ /dev/null @@ -1,14 +0,0 @@ -#!/usr/bin/env bash - -# Get the weather for the given location. - -location=${1:-Cincinnati} -shouldContinue="1" - -while [[ $shouldContinue == "1" ]]; do - echo -e "\e[H\e[2J" # clears the screen. - curl "wttr.in/$1" - shouldContinue=$(gum confirm "Quit / Refresh" --affirmative Quit --negative Refresh && echo "0" || echo "1") -done - -echo -e "\e[H\e[2J" # clears the screen. diff --git a/env/.local/scripts/weather b/env/.local/scripts/weather new file mode 100755 index 0000000..9cb1e57 --- /dev/null +++ b/env/.local/scripts/weather @@ -0,0 +1,78 @@ +#!/usr/bin/env bash + +usage() { + cat < + +OPTIONS: + + -i | --interactve: Prompts user to quit or refresh, which keeps the terminal alive until user quits. + -l | --launch: Launches the interactive option in a new ghostty terminal. + --window-class : Optional window class used only with launch command [default: com.ghostty.weather] + --window-padding-x : Optional window padding used only with launch command [default: 10] + -h | --help: Show usage. + +EOF +} + +location="Cincinnati" +interactive_flag="0" +launch_flag="0" +should_continue="0" +window_class="com.ghostty.weather" +window_padding_x="10" + +while [[ $# -gt 0 ]]; do + if [[ $1 =~ ^-i ]] || [[ $1 =~ ^--interactive ]]; then + interactive_flag="1" + elif [[ $1 =~ ^-h ]] || [[ $1 =~ ^--help ]]; then + usage && exit 0 + elif [[ $1 =~ ^-l ]] || [[ $1 =~ ^--launch ]]; then + launch_flag="1" + elif [[ $1 =~ ^--window-class ]]; then + shift + window_class=$1 + elif [[ $1 =~ ^--window-padding-x ]]; then + shift + window_padding_x=$1 + else + location=$1 + fi + shift +done + +get_weather() { + curl "wttr.in/$location" +} + +################################################## +# MAIN +################################################## + +if [[ -z $location ]]; then + # Fail if we don't have a location. + echo -e "\n[ERROR]: Invalid location" + usage && exit 1 +elif [[ $launch_flag == "1" ]]; then + # Launch a new window and call this script with --interactive flag set, so the window stays open until the user quits. + ghostty --class=$window_class --window-padding-x=$window_padding_x \ + --keybind="j=scroll_page_fractional:0.5" --keybind="k=scroll_page_fractional:-0.5" \ + --keybind="q=quit" \ + -e ${BASH_SOURCE[0]} --interactive + +elif [[ $interactive_flag == "1" ]]; then + # Interactive mode starts a loop until the user quits. It prompts them to quit or refresh the weather results. + while [[ $should_continue == "0" ]]; do + echo "Fetching weather for: $location" + get_weather + # Set's should_continue to '0' if when user hits the quit option or '1' if the hit refresh. + should_continue=$(gum confirm "Weather: $location" --affirmative Refresh --negative Quit && echo "0" || echo "1") + done +else + # Just show the weather in normal mode. + get_weather +fi diff --git a/env/.local/share/applications/weather.desktop b/env/.local/share/applications/weather.desktop old mode 100644 new mode 100755 index 5de74e5..88bd69b --- a/env/.local/share/applications/weather.desktop +++ b/env/.local/share/applications/weather.desktop @@ -2,7 +2,7 @@ Version=1.0 Name=Weather Comment=Get weather -Exec=ghostty --class=com.ghostty.weather -e /home/michael/.local/scripts/get-weather +Exec=/home/michael/.local/scripts/weather --launch Icon=/home/michael/.local/share/applications/icons/weather.png Terminal=false Type=Application