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
don't add --exclude-dir to GREP_OPTIONS on FreeBSD #2650
Conversation
kemko
commented
Mar 24, 2014
•
edited by mcornella
edited by mcornella
perhaps in ports have a more recent version of the grep, but in basic installation only this. |
Same problem with OSx 10.7 (GNU grep v2.5.1) Fixed using with brew (GNU grep v2.18): brew install grep
ln -s /usr/local/opt/grep/bin/ggrep /usr/local/bin/grep |
@kemko You confirm my diagnostic: you need |
@ncanceill Version 2.5.2 can be obtained only by setting its from ports (analogue to brew on OSx). If that means - no problem. But I was hoping that OMZ can work on supported systems without installing additional software. |
It seems reasonable to only use |
Version 2.5.1 is nine years old! Sorry the official FreeBSD repo is so old. Anyway, I would definitely recommend upgrading via |
Oh my zsh broke my grep on all my systems too, FreeBSD |
On the other hand, as @ncanceill says it's in your best interest to upgrade your |
On OS X 1.7.5, after upgrading grep to 2.18 via homebrew, and doing
Is it necessary to perform some other step to remove this message? |
@mcornella I have not yet needed to use new options like The first patch was made in haste. Now slightly rewrited it for cases where the system has a It isn't big deal to copy some workaround for this issue into my own .zshrc and forget about it, but I guess I did not mention that installation from ports is also used |
@ncanceill Is that better? upd: Answer himself. Poor checked on Linux, this code says that version 2.14 is less than 2.5.2 |
Yes you have switched the arguments: it should be is-at-least 2.5.2 $GREP_VERSION Also, maybe you can add a comment to explain that |
This worked for me on OSX 10.7.5:
The default brew install of grep prefixes the command with Hope that helps. |
@ncanceill Tried to correct all the flaws. |
That worked perfectly. Nice job! 👍 |
Looks good to me too! 👍 |
Wow, this one scared the bejeezus out of me, I thought my box was rooted when all of a sudden grep started spewing errors. Good thing I found this just in time before I completely reinstalled my box. |
Those patches worked for me (OS X 10.6.8). |
|
Hi @kriogenx0, thank you for contributing. Nonetheless, I am afraid you are wrong. In the end, I fail to see what you seek to improve in this PR with your comment. Mistake 1`grep -V | grep GNU | awk '{print $4}'` This is not enough: Mistake 2if [[ $GREP_VERSION > 2.5.2 ]] This does not work: it does alphanumerical ordering, which is not what is needed. For instance, |
This fixes the problem for me! Running OS X 10.6.8 |
Nice version parsing! Fixes the problem for me. |
Is the If you can confirm at least a version range, it could be included. |
I have just updated oh-my-zsh to the last version and get that error too on MacOSX 10.7.4
I don't get if i need to manually modify something or if the patch will be rolled out on the next release |
Suggested patch: ...
# --exclude-dir is only available on 2.5.3 and later versions of grep
if grep --exclude-dir=.svn 2>&1 >/dev/null;
then
for PATTERN in .cvs .git .hg .svn; do
GREP_OPTIONS+="--exclude-dir=$PATTERN "
done
fi
...
|
|
Nice idea, first test if |
@kemko grep --exclude-dir=.svn >/dev/null 2>&1 && echo "good grep" || echo "bad grep" |
@labeneator my grep is "bad", but it's 2.14 and support |
@labeneator you need to provide PATTERN and an input (so a FILE argument or pass it from a pipe). I have What @kemko said 😁 |
@kemko, @mcornella, I see what you are saying. So the best test we have is something along the lines of: if echo hello | grep --exclude-dir=.git -nire hello >/dev/null 2>&1;
then
echo "Set GREP_OPTIONS"
fi Turns out that OSX Mavericks' grep which is version 2.5.1 supports --exclude-dir. $ which grep
/usr/bin/grep
$ /usr/bin/grep --version
grep (BSD grep) 2.5.1-FreeBSD
$ git init /tmp/git-test
Initialized empty Git repository in /private/tmp/git-test/.git/
$ echo hello > /tmp/git-test/something
$ echo hello > /tmp/git-test/git-it
# Works as expected. .git is skipped.
$ grep --exclude-dir=.git -nire h /tmp/git-test
/tmp/git-test/git-it:1:hello
/tmp/git-test/something:1:hello
$ grep -nire h /tmp/git-test | head -3
/tmp/git-test/.git/description:1:Unnamed repository; edit this file 'description' to name the repository.
/tmp/git-test/.git/HEAD:1:ref: refs/heads/master
/tmp/git-test/.git/hooks/applypatch-msg.sample:1:#!/bin/sh
$ GREP_OPTIONS="--exclude-dir=.git"
$ grep -nire h /tmp/git-test | head -3
/tmp/git-test/git-it:1:hello
/tmp/git-test/something:1:hello |
@ncanceill It worked for me, thanks |
I have cleaned @labeneator's proposal a bit, so the whole file looks like this (I rearranged a couple of lines too to make it prettier) #
# Color grep results
# Examples: http://rubyurl.com/ZXv
#
GREP_OPTIONS="--color=auto"
# avoid VCS folders (if the necessary grep flags are available)
grep-flag-available() {
echo | grep $1 "" >/dev/null 2>&1
}
if grep-flag-available --exclude-dir=.cvs; then
for PATTERN in .cvs .git .hg .svn; do
GREP_OPTIONS+=" --exclude-dir=$PATTERN"
done
elif grep-flag-available --exclude=.cvs; then
for PATTERN in .cvs .git .hg .svn; do
GREP_OPTIONS+=" --exclude=$PATTERN"
done
fi
unfunction grep-flag-available
export GREP_OPTIONS="$GREP_OPTIONS"
export GREP_COLOR='1;32' |
@mcornella Nice 👍 |
👍 @mcornella's version @kemko can you update the PR? |
Works for me too. Ship it.
|
Seems I was a bit late with submitting my patch (#2720) but @mcornella's works with |
@ncanceill done |
Amazing! @robbyrussell this PR is so needed and ready for merge |
Hitting this on OS X - please fix asap. |
@ncanceill I tried. I hope I did everything right. for now i'm tried: git clone git@github.com:kemko/oh-my-zsh |
Not exactly.. Maybe you were still on your Otherwise, closing this PR and creating a new one from a clean branch with just that one exclude-dir commit might be easier ;) |
think I figured out what was wrong. Is that better? |
That looks right to me and a fresh pull works just swell. (freebsd 9.1) Thanks @kemko |
Yes, that's cleaner, thanks! |
Perfect! 👍 Safe to merge @robbyrussell |
don't add --exclude-dir to GREP_OPTIONS on FreeBSD