sainnhe/tmux-fzf

macOS's version of sed doesn't support "-r" flag, but instead "-E"

camspiers opened this issue · 8 comments

The workaround is to use gnu-sed from brew, and make sure that the path to the homebrew version is ahead of the system sed. But perhaps you could do some environment detection by seeing whether the sed version available on a users path is one that supports -E or -r?

Love the tool!

It's a bit difficult for me to support the buildin sed on mac OS, because

  1. I don't have a mac, so I'm unable to test the buildin sed.
  2. Almost all code that uses sed needs to be retested, this is not an easy job.

But simple version detection should still be easy to do.

What about using this code, could you test it on your mac OS?

if [[ "$(sed --version | head -n 1 | grep -o GNU)" == "GNU" ]]; then
    echo "GNU"
else
    echo "buildin"
fi

It looks like sed on macOS (at least Catalina) doesn't have the --version option.

✦2 ➜ /usr/bin/sed --version
/usr/bin/sed: illegal option -- -
usage: sed script [-Ealn] [-i extension] [file ...]
       sed [-Ealn] [-i extension] [-e script] ... [-f script_file] ... [file ...]

Don't feel like this is critical. Maybe a minimum first fix is documenting how to use gnu-sed from homebrew (most folks will be using brew if they are using tmux on macOS), and perhaps allowing the path for sed to come from a variable (in case folks don't want to make gnu-sed their system default).

For what it is worth, these are the installation steps I took:

Install gnu-sed

 brew install gnu-sed

Make gnu-sed the default sed on your $PATH

Open ~/.bash_profile, and add the following, or equivalent:

export PATH="/usr/local/opt/gnu-sed/libexec/gnubin:$PATH"

Technically, if you make sure you capture stderr in the above so it doesn't spew the error what you have written should actually work fine. I've tested the following with both versions on my $PATH successively, and it works fine:

if [[ "$(sed --version 2> /dev/null | head -n 1 | grep -o GNU)" == "GNU" ]]; then
    echo "GNU"
else
    echo "buildin"
fi

I've updated this plugin 5e5e057.

The README has been updated, a new option named TMUX_FZF_SED has been added and the version detection of sed has been supported.

Wow! This is awesome. Thanks so much. I consider this issue closed, if you ever decide to attempt macOS sed compatibility, we can use a new task for it.

Wouldn't this issue be moot by just using -E instead of -r? GNU sed supports -E and -E is the POSIX standard anyway.

From sed --help:

-E, -r, --regexp-extended
use extended regular expressions in the script
(for portability use POSIX -E).