Skip to content
Open
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
126 changes: 78 additions & 48 deletions segments/weather.sh
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@ TMUX_POWERLINE_SEG_WEATHER_UPDATE_PERIOD_DEFAULT="600"
TMUX_POWERLINE_SEG_WEATHER_LOCATION_UPDATE_PERIOD_DEFAULT="86400" # 24 hours
TMUX_POWERLINE_SEG_WEATHER_LAT_DEFAULT="auto"
TMUX_POWERLINE_SEG_WEATHER_LON_DEFAULT="auto"
# Icon style: "emoji" (default), "nerdfonts", "emoji_fixed", "auto"
TMUX_POWERLINE_SEG_WEATHER_ICON_STYLE_DEFAULT="emoji"
Comment on lines +14 to +15
Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please fix this


# Global cache file for weather data
TMUX_POWERLINE_SEG_WEATHER_CACHE_FILE_WEATHER="${TMUX_POWERLINE_DIR_TEMPORARY}/weather_cache_data.txt"
Expand All @@ -34,6 +36,12 @@ export TMUX_POWERLINE_SEG_WEATHER_LOCATION_UPDATE_PERIOD="${TMUX_POWERLINE_SEG_W
# Set both to "auto" to detect automatically based on your IP address, or set them manually
export TMUX_POWERLINE_SEG_WEATHER_LAT="${TMUX_POWERLINE_SEG_WEATHER_LAT_DEFAULT}"
export TMUX_POWERLINE_SEG_WEATHER_LON="${TMUX_POWERLINE_SEG_WEATHER_LON_DEFAULT}"
# Icon style for weather condition symbols:
# "emoji" - emoji with VS16 variation selector (default, original behaviour)
# "emoji_fixed" - emoji with VS16 stripped; use if tmux miscounts status-bar width
# "nerdfonts" - Nerd Font PUA icons (1 cell, no width ambiguity)
# "auto" - nerdfonts when a patched font is detected, else emoji
export TMUX_POWERLINE_SEG_WEATHER_ICON_STYLE="${TMUX_POWERLINE_SEG_WEATHER_ICON_STYLE_DEFAULT}"
EORC
echo "$rccontents"
}
Expand Down Expand Up @@ -80,6 +88,9 @@ __process_settings() {
if [ -z "$TMUX_POWERLINE_SEG_WEATHER_LOCATION_UPDATE_PERIOD" ]; then
export TMUX_POWERLINE_SEG_WEATHER_LOCATION_UPDATE_PERIOD="${TMUX_POWERLINE_SEG_WEATHER_LOCATION_UPDATE_PERIOD_DEFAULT}"
fi
if [ -z "$TMUX_POWERLINE_SEG_WEATHER_ICON_STYLE" ]; then
export TMUX_POWERLINE_SEG_WEATHER_ICON_STYLE="${TMUX_POWERLINE_SEG_WEATHER_ICON_STYLE_DEFAULT}"
fi
if [ "$TMUX_POWERLINE_SEG_WEATHER_LAT" = "auto" ] || [ "$TMUX_POWERLINE_SEG_WEATHER_LON" = "auto" ] || [ -z "$TMUX_POWERLINE_SEG_WEATHER_LON" ] || [ -z "$TMUX_POWERLINE_SEG_WEATHER_LAT" ]; then
if ! __get_auto_location; then
exit 8
Expand Down Expand Up @@ -134,8 +145,13 @@ __yrno() {
if [ "$TMUX_POWERLINE_SEG_WEATHER_UNIT" == "f" ]; then
degree=$(__degree_c2f "$degree")
fi
local icon_style="${TMUX_POWERLINE_SEG_WEATHER_ICON_STYLE:-$TMUX_POWERLINE_SEG_WEATHER_ICON_STYLE_DEFAULT}"
if [ "$icon_style" = "auto" ]; then
tp_patched_font_in_use && icon_style="nerdfonts" || icon_style="emoji"
fi
# condition_symbol=$(__get_yrno_condition_symbol "$condition" "$sunrise" "$sunset")
condition_symbol=$(__get_yrno_condition_symbol "$condition")
local condition_symbol
condition_symbol=$(__get_yrno_condition_symbol "$condition" "$icon_style")
Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@turtle11311 please address this

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed — icon style is now resolved at the top of run_segment() before the cache read, and the cache file path encodes the style (weather_cache_data_${icon_style}.txt). Switching TMUX_POWERLINE_SEG_WEATHER_ICON_STYLE takes effect immediately without waiting for the cache to expire.

# Write the <content@date>, separated by a @ character, so we can fetch it later on without having to call 'stat'
echo "${condition_symbol} ${degree}°$(echo "$TMUX_POWERLINE_SEG_WEATHER_UNIT" | tr '[:lower:]' '[:upper:]')"
}
Expand All @@ -161,53 +177,67 @@ __get_yrno_condition_symbol() {
# local sunrise="$2"
# local sunset="$3"
local condition=$1
case "$condition" in
"clearsky_day")
echo "☀️ "
;;
"clearsky_night")
echo "🌙"
;;
"fair_day")
echo "🌤 "
;;
"fair_night")
echo "🌜"
;;
"fog")
echo "🌫 "
;;
"cloudy")
echo "☁️ "
;;
"rain" | "lightrain" | "heavyrain" | "sleet" | "lightsleet" | "heavysleet")
echo "🌧 "
;;
"heavyrainandthunder" | "heavyrainshowersandthunder_day" | "heavyrainshowersandthunder_night" | "heavysleetandthunder" | "heavysleetshowersandthunder_day" | "heavysnowandthunder" | "heavysnowshowersandthunder_day" | "heavysnowshowersandthunder_night" | "lightrainandthunder" | "lightrainshowersandthunder_day" | "lightrainshowersandthunder_night" | "lightsleetandthunder" | "lightsnowandthunder" | "lightssleetshowersandthunder_day" | "lightssleetshowersandthunder_night" | "lightssnowshowersandthunder_day" | "lightssnowshowersandthunder_night" | "rainandthunder" | "rainshowersandthunder_day" | "rainshowersandthunder_night" | "sleetandthunder" | "sleetshowersandthunder_day" | "sleetshowersandthunder_night" | "snowandthunder" | "snowshowersandthunder_day" | "snowshowersandthunder_night")
echo "⛈️ "
;;
"heavyrainshowers_day" | "heavysleetshowers_day" | "heavysleetshowersandthunder_night" | "lightrainshowers_day" | "lightsleetshowers_day" | "rainshowers_day" | "sleetshowers_day")
echo "🌦️ "
;;
"heavyrainshowers_night" | "heavysleetshowers_night" | "lightrainshowers_night" | "lightsleetshowers_night" | "rainshowers_night" | "sleetshowers_night")
echo "☔"
;;
"snow" | "lightsnow" | "heavysnow")
echo "❄️ "
;;
"lightsnowshowers_day" | "lightsnowshowers_night" | "heavysnowshowers_day" | "heavysnowshowers_night" | "snowshowers_day" | "snowshowers_night")
echo "🌨 "
;;
"partlycloudy_day")
echo "⛅"
;;
"partlycloudy_night")
echo "🌗"
;;
*)
echo "?"
;;
esac
local style="${2:-emoji}"

if [ "$style" = "nerdfonts" ]; then
# All Nerd Font icons are PUA (1 cell), no width ambiguity
case "$condition" in
"clearsky_day") printf "\UF0599" ;; # 󰖙 mdi-weather-sunny
Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@turtle11311 please address this

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed — replaced all printf "\\UF..." calls with literal UTF-8 glyphs embedded directly in the source file. Bash 3.2-safe.

Also took this opportunity to fix the related portability issue raised in the adjacent Copilot comment (line 236): the sed 's/\xef\xb8\x8f//g' VS16-stripping (GNU sed only) has been replaced with an explicit emoji_fixed lookup table that pre-defines each symbol without VS16, so no sed is needed at all.

"clearsky_night") printf "\UF0594" ;; # 󰖔 mdi-weather-night
"fair_day") printf "\UF0595" ;; # 󰖕 mdi-weather-partly-cloudy
"fair_night") printf "\UF0F31" ;; # 󰼱 mdi-weather-night-partly-cloudy
"fog") printf "\UF0591" ;; # 󰖑 mdi-weather-fog
"cloudy") printf "\UF0590" ;; # 󰖐 mdi-weather-cloudy
"rain" | "lightrain" | "heavyrain" | "sleet" | "lightsleet" | "heavysleet")
printf "\UF0597" ;; # 󰖗 mdi-weather-rainy
"heavyrainandthunder" | "heavyrainshowersandthunder_day" | "heavyrainshowersandthunder_night" | "heavysleetandthunder" | "heavysleetshowersandthunder_day" | "heavysnowandthunder" | "heavysnowshowersandthunder_day" | "heavysnowshowersandthunder_night" | "lightrainandthunder" | "lightrainshowersandthunder_day" | "lightrainshowersandthunder_night" | "lightsleetandthunder" | "lightsnowandthunder" | "lightssleetshowersandthunder_day" | "lightssleetshowersandthunder_night" | "lightssnowshowersandthunder_day" | "lightssnowshowersandthunder_night" | "rainandthunder" | "rainshowersandthunder_day" | "rainshowersandthunder_night" | "sleetandthunder" | "sleetshowersandthunder_day" | "sleetshowersandthunder_night" | "snowandthunder" | "snowshowersandthunder_day" | "snowshowersandthunder_night")
printf "\UF067E" ;; # 󰙾 mdi-weather-lightning-rainy
"heavyrainshowers_day" | "heavysleetshowers_day" | "heavysleetshowersandthunder_night" | "lightrainshowers_day" | "lightsleetshowers_day" | "rainshowers_day" | "sleetshowers_day")
Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@turtle11311 please address this

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed — heavysleetshowersandthunder_night moved into the thunder/lightning group across all three style branches (nerdfonts, emoji_fixed, emoji).

printf "\UF0F33" ;; # 󰼳 mdi-weather-partly-rainy
"heavyrainshowers_night" | "heavysleetshowers_night" | "lightrainshowers_night" | "lightsleetshowers_night" | "rainshowers_night" | "sleetshowers_night")
printf "\UF0597" ;; # 󰖗 mdi-weather-rainy
"snow" | "lightsnow" | "heavysnow")
printf "\UF0598" ;; # 󰖘 mdi-weather-snowy
"lightsnowshowers_day" | "lightsnowshowers_night" | "heavysnowshowers_day" | "heavysnowshowers_night" | "snowshowers_day" | "snowshowers_night")
printf "\UF0F34" ;; # 󰼴 mdi-weather-partly-snowy
"partlycloudy_day") printf "\UF0595" ;; # 󰖕 mdi-weather-partly-cloudy
"partlycloudy_night") printf "\UF0F31" ;; # 󰼱 mdi-weather-night-partly-cloudy
*) echo "?" ;;
esac
else
# emoji / emoji_fixed: original symbols with VS16 variation selectors.
# "emoji_fixed" strips VS16 (U+FE0F) for terminals where Neutral-width base
# chars like ☀ (U+2600) + VS16 cause tmux to miscalculate status-bar width.
local symbol
case "$condition" in
"clearsky_day") symbol="☀️ " ;;
"clearsky_night") symbol="🌙" ;;
"fair_day") symbol="🌤 " ;;
"fair_night") symbol="🌜" ;;
"fog") symbol="🌫 " ;;
"cloudy") symbol="☁️ " ;;
"rain" | "lightrain" | "heavyrain" | "sleet" | "lightsleet" | "heavysleet")
symbol="🌧 " ;;
"heavyrainandthunder" | "heavyrainshowersandthunder_day" | "heavyrainshowersandthunder_night" | "heavysleetandthunder" | "heavysleetshowersandthunder_day" | "heavysnowandthunder" | "heavysnowshowersandthunder_day" | "heavysnowshowersandthunder_night" | "lightrainandthunder" | "lightrainshowersandthunder_day" | "lightrainshowersandthunder_night" | "lightsleetandthunder" | "lightsnowandthunder" | "lightssleetshowersandthunder_day" | "lightssleetshowersandthunder_night" | "lightssnowshowersandthunder_day" | "lightssnowshowersandthunder_night" | "rainandthunder" | "rainshowersandthunder_day" | "rainshowersandthunder_night" | "sleetandthunder" | "sleetshowersandthunder_day" | "sleetshowersandthunder_night" | "snowandthunder" | "snowshowersandthunder_day" | "snowshowersandthunder_night")
symbol="⛈️ " ;;
"heavyrainshowers_day" | "heavysleetshowers_day" | "heavysleetshowersandthunder_night" | "lightrainshowers_day" | "lightsleetshowers_day" | "rainshowers_day" | "sleetshowers_day")
symbol="🌦️ " ;;
"heavyrainshowers_night" | "heavysleetshowers_night" | "lightrainshowers_night" | "lightsleetshowers_night" | "rainshowers_night" | "sleetshowers_night")
symbol="☔" ;;
"snow" | "lightsnow" | "heavysnow")
symbol="❄️ " ;;
"lightsnowshowers_day" | "lightsnowshowers_night" | "heavysnowshowers_day" | "heavysnowshowers_night" | "snowshowers_day" | "snowshowers_night")
symbol="🌨 " ;;
"partlycloudy_day") symbol="⛅" ;;
"partlycloudy_night") symbol="🌗" ;;
*) symbol="?" ;;
esac
if [ "$style" = "emoji_fixed" ]; then
printf '%s' "$symbol" | sed 's/\xef\xb8\x8f//g'
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed — the entire sed-based approach has been dropped. emoji_fixed is now a standalone lookup table with the VS16-free symbols pre-defined, so no post-processing is needed at all.

else
printf '%s' "$symbol"
fi
fi
}


Expand Down
Loading