Closed mathieu-lemay closed 2 years ago
This feels like an ugly hack, I'm open to improvements!
You can see the difference in behavior with this command: echo foo | grep -vf /dev/null; echo "exit code: $?"
# Linux
$ echo foo | grep -vf /dev/null; echo "exit code: $?"
foo
exit code: 0
# macOS
$ echo foo | grep -vf /dev/null; echo "exit code: $?"
exit code: 1
Is this also because of an old macOS version?
$ sw_vers
ProductName: macOS
ProductVersion: 12.4
BuildVersion: 21F79
$ echo foo | grep -vf /dev/null; echo "exit code: $?"
foo
exit code: 0
I wasn't sure but if it works for you in macOS 12.4, then it must be.
I have the issue in macOS 10.15.
I think we should just tell the users running old macOS to install GNU grep (brew install grep
) instead of special-casing each invocation of it, then the script can pick up ggrep
if it's found.
Anyway, I've realized the current code needs fixing.
# 10 is not printed because if matches '1'
seq 10 | grep -vFf <(seq 5)
Let me see what I can do.
So we need -x
as well.
seq 10 | grep -vxFf <(seq 5)
-x, --line-regexp Only input lines selected against an entire fixed string or regular expression are considered to be matching lines.
On both Linux and macOS,
grep -f
will match nothing when provided with an empty file. However, unlike on Linux, when combined with-v
, grep on macOS will not match everything when provided with an empty file while the-v
flag is active. This results in_fzf_git_files
being empty when in a clean repository.This fixes this behaviour by bypassing the grep command if there is nothing to exclude.