Skip to content
New issue

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

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

Already on GitHub? # to your account

Issues on macos if gnused isn't installed as "gsed" #101

Closed
jay-aye-see-kay opened this issue Jan 23, 2023 · 2 comments
Closed

Issues on macos if gnused isn't installed as "gsed" #101

jay-aye-see-kay opened this issue Jan 23, 2023 · 2 comments
Labels
wontfix This will not be worked on

Comments

@jay-aye-see-kay
Copy link

Really enjoying this plugin, thanks so much for making it.

I'm using it on Linux and Mac. Linux no issues, but I don't use homebrew on my macbook, I install all my packages through nix + home-manager. This means I have gnused installed as sed and no binary gsed. And that causes two issues:

  1. I get a warning from here that I don't have gnused installed (this isn't blocking, but is mildly annoying).
  2. When I go to actually do a replacement on a Mac I get a gsed not found error. This part can be worked around by setting require("spectre").setup({ replace_engine = { sed = { cmd = "sed" } } }) but it took me a while to figure out this solution.

There doesn't seem to be any "standard" solution to checking if the binary sed is the GNU or BSD version on any particular system, but that seems like the actual check that should be done. Maybe doing something like vim.fn.system("sed --version | grep GNU") as a check would work.

Or maybe it's easier to just add a print_warnings option that defaults to true and people can override the sed command in setup().

The workaround I ended up going with was creating a gsed binary that calls sed on my system (included below for any other nix on mac users). But I thought I'd report the issue in case you had the appetite to improve the "sed type detection" part (I also wonder what would happen on a *BSD OS or busybox based linux, those probably have non-gnu sed too).

{ pkgs, ... }: {
  environment.systemPackages = [
    pkgs.gnused
    (pkgs.writeShellScriptBin "gsed" "exec ${pkgs.gnused}/bin/sed")
  ];
}
@stale
Copy link

stale bot commented Mar 24, 2023

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.

@stale stale bot added the wontfix This will not be worked on label Mar 24, 2023
@stale stale bot closed this as completed Apr 1, 2023
@dinvlad
Copy link
Contributor

dinvlad commented Sep 3, 2023

For anyone finding this later, there's a missing "$@" in the above command (note: quotes are also important!):

(pkgs.writeShellScriptBin "gsed" "exec ${pkgs.gnused}/bin/sed \"$@\"")

Without this, no arguments will be passed to sed, which will then fail and result in a cryptic [] ERROR [] ERROR [] ERROR [] ERROR [] ERROR ... message from replace, like in the screenshot from this issue: #141 (comment). I've spent an embarrassing amount of time to find this out the hard way..

# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
wontfix This will not be worked on
Projects
None yet
Development

No branches or pull requests

2 participants