Skip to content

The Weather Segment (segments/weather.sh) does not work on MacOS despite using to GNU grep with Perl regular expression enabled #465

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
onlyuuuuu opened this issue Apr 17, 2025 · 4 comments · Fixed by #468

Comments

@onlyuuuuu
Copy link

Desc

I'm on my Mac M1 and I was trying to setup my TMUX powerline with my own configurations according to the documentation. Everything goes well until one the segments, which is the weather.sh segment does seem to loaded up, no outputting text, just a small gap with blank content.

Upon further investigation, I've noticed that I'm using an unsupported grep with no -P (Perl expression support). Which is grep (BSD grep, GNU compatible) 2.6.0-FreeBSD. This is expected and have been mentioned in the documentation.

The solution will be to set the variable TMUX_POWERLINE_SEG_WEATHER_GREP=ggrep in my config.sh file since I'm using Homebrew and have ggrep installed, which is the GNU Grep and supported the -P (Perl expression support). However, the settings never get applied due to the implementation never applies the value of the variable and used it.

Proposals

The fix to this should be applied on line 97 from

grep=$TMUX_POWERLINE_SEG_WEATHER_GREP_DEFAULT

to

grep=$TMUX_POWERLINE_SEG_WEATHER_GREP

Other Proposals/Issues

On debugging and setting up the Weather segment. I've also found some other minor problems, such as:

  1. The desc/docs on the segments has some outdated and misleading info. For ex:
# The data provider to use. Currently only "yahoo" is supported.
export TMUX_POWERLINE_SEG_WEATHER_DATA_PROVIDER="${TMUX_POWERLINE_SEG_WEATHER_DATA_PROVIDER_DEFAULT}"

Should be

# The data provider to use. Currently only "yrno" is supported.
export TMUX_POWERLINE_SEG_WEATHER_DATA_PROVIDER="${TMUX_POWERLINE_SEG_WEATHER_DATA_PROVIDER_DEFAULT}"
  1. There are MacOS users, like me, uses tools from Homebrew GNU CoreUtils instead of the shitty FreeBDS stuff. So the stat command on line 83
if shell_is_osx || shell_is_bsd; then
  last_update=$(stat -f "%m" "${tmp_file}")

doesn't work since we've sourced the CoreUtils stuff over the FreeBDS stuff (by writting it at the beginning of $PATH). So I have to do a workaround and added an entry in config.sh to something like this

# 'stat' command needs to be from /usr/bin/stat in other for weather.sh to work
export PATH="/usr/bin:$PATH"

Just to get Powerline to use the FreeBDS stat command. Maybe fixing this won't ideal, but something/tips mentioned in the docs might be useful for pp that might or have ran into this problem like me. Just to save up hours of debugging.

  1. If you set LAT and LON both to auto. There's a chance that you might get API rate limiting on https://ipapi.co/json. So there's nothing you can do about it by manually setting the actual coordinates.

Last words

Thank you for all the pp that maintains such a great project and I love every bit of it. Debugging and troubleshooting this has been a fun experience for me. This is my first ever GitHub issues that I've ever submitted to any projects so sorry for the words, I didn't mean to offend anybody. I can cook up a PR if possible.

@erikw
Copy link
Owner

erikw commented Apr 17, 2025

Oh that -P switch! I actually though of this when I reviewed #464 that was merged just recently. As I looked at the PR I rememberd this switch is only avaialble in GNU Grep. But I saw that it says in README that this segment requires gnu grep so I though it would be safe..

But you are right. This line

grep=$TMUX_POWERLINE_SEG_WEATHER_GREP_DEFAULT

is wrong, should use the configure not the default grep.

Additionally these grep usages should use the configure grep as well:

TMUX_POWERLINE_SEG_WEATHER_LAT=$(grep -oP "(?<=TMUX_POWERLINE_SEG_WEATHER_LAT=')[^']*" "$cache_file")
TMUX_POWERLINE_SEG_WEATHER_LON=$(grep -oP "(?<=TMUX_POWERLINE_SEG_WEATHER_LON=')[^']*" "$cache_file")

TMUX_POWERLINE_SEG_WEATHER_LAT=$(grep -oP "(?<=TMUX_POWERLINE_SEG_WEATHER_LAT=')[^']*" "$cache_file")
TMUX_POWERLINE_SEG_WEATHER_LON=$(grep -oP "(?<=TMUX_POWERLINE_SEG_WEATHER_LON=')[^']*" "$cache_file")

Looping in @jackdeye for information sharing.

If you could make a PR that would be awesome @onlyuuuuu. Maybe you could add a note in the README for the weather segment on how to properly set it up on macOS nowadays.

Usually I'm on a mac system but for the last and comming months I'm not, so I can't check myself.

@erikw
Copy link
Owner

erikw commented Apr 17, 2025

Oh I forgot the most obvious approach: the best thing would of course be to rewrite all grep lines to use only features compatible with both BSD and GNU version of grep. Or alternative standard shell commands.

I would say this is the better approach!

@onlyuuuuu
Copy link
Author

Yep, totally agree, I'm writing up a fix now

@onlyuuuuu
Copy link
Author

Done PR created here: #466
Descriptions are written in the PR. If you can have a look, that be great @erikw. Tks

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants