Skip to content

Conversation

@pcrock-thmdo
Copy link
Contributor

@pcrock-thmdo pcrock-thmdo commented Mar 20, 2025

not all macOS users have gsed installed, so we need to just do the BSD-flavored sed incantation

UPDATE: or maybe awk gets rid of some cross-platform jank...

❗ needs testing on macOS!

not all macOS users have gsed installed, so we need to just do the
BSD-flavored `sed` incantation
@pcrock-thmdo pcrock-thmdo self-assigned this Mar 20, 2025
@pcrock-thmdo pcrock-thmdo marked this pull request as ready for review March 20, 2025 16:18
@pcrock-thmdo pcrock-thmdo requested a review from a team as a code owner March 20, 2025 16:18
Copy link

@sbresin sbresin left a comment

Choose a reason for hiding this comment

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

i am using macOS, but my sed command comes from nix and is the GNU variant.
so this would break for me in this case.

i guess you would need to check something like sed --help | grep GNU to either be a 0 or error out to be sure which one you have.

In this case i wonder though if this should not work for both variants

sed -i -E '/^$/N;/^\n$/D' the lowercase -i works the same on both variants and the capital -E should as well

@pcrock-thmdo
Copy link
Contributor Author

lowercase -i works the same on both variants

it exists in both variants, but behaves differently in both variants. see https://stackoverflow.com/a/4247319/138757.

i am considering moving to perl then, but you're right, the --help or --version approach might work better than the uname approach.

also... never thought about nix! thanks for adding that perspective @sbresin

@sbresin
Copy link

sbresin commented Mar 21, 2025

One more thing. I will move to uutils-coreutils soon and ubuntu for example is planning to do as well. So theres even one player more, even though this one ist GNU compatible.
So you would need to detect just the BSD variant and treat it different.

@pcrock-thmdo pcrock-thmdo requested a review from sbresin March 21, 2025 14:44
Copy link

@sbresin sbresin left a comment

Choose a reason for hiding this comment

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

If you are writing to the file using redirection you could have just used sed without the -i flag. But i am fine with it either way

@syphar
Copy link
Member

syphar commented Mar 24, 2025

general note here:

in the future we just have to balance when it's ok to tell people "you need gsed on a mac", compared to how many hoops we want to jump through to make it work with BSD sed

@pcrock-thmdo
Copy link
Contributor Author

If you are writing to the file using redirection you could have just used sed without the -i flag.

oh yeah. duh. 🙄 🤦

@pcrock-thmdo pcrock-thmdo merged commit 0857a9d into main Mar 25, 2025
1 check passed
@pcrock-thmdo pcrock-thmdo deleted the cross-platform-sed branch March 25, 2025 09:01
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 this pull request may close these issues.

4 participants