Skip to content
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

counsel-git-grep does not accept spaces in search string #1176

Closed
noorul opened this issue Aug 29, 2017 · 6 comments
Closed

counsel-git-grep does not accept spaces in search string #1176

noorul opened this issue Aug 29, 2017 · 6 comments

Comments

@noorul
Copy link

noorul commented Aug 29, 2017

The following command works in command line

git --no-pager grep --full-name -n --no-color -i -e 'def test_'

But when I try to search 'def test' using counsel-git-grep, it returns nothing.

@abo-abo
Copy link
Owner

abo-abo commented Aug 29, 2017

Are you using custom counsel settings? I'm using the defaults, which translate the input def test into the regex def.*test. You can get literal spaces by stacking multiple spaces: two spaces in a row match a single space etc.

In your input, the trailing space doesn't matter, the final regex given to the shell should be the same as for input def test.

@noorul
Copy link
Author

noorul commented Aug 30, 2017

I had a custom setting. I removed it and it works now, but it does not give the desired output.

When I use the following

git --no-pager grep --full-name -n --no-color -i -e 'def test_'

It gives me only the ones start with "def test_" but counsel returns more like the ones with def generate_test_data() too. I am not sure why counsel is not passing the string as it is to git-grep

@dgchurchill
Copy link

I seem to have a related problem. I'm on Windows, with counsel-git-grep-skip-counting-lines set to its default of nil. This means counsel--git-grep-count gets initialized to 0 in counsel-git-grep. Then in counsel-git-grep-function the condition (or counsel-git-grep-skip-counting-lines (> counsel--git-grep-count 20000)) evaluates to nil meaning the (counsel-more-chars 3) check is skipped and the executed command is git --no-pager grep --full-name -n --no-color -i -e ''.

Setting counsel-git-grep-skip-counting-lines to t seems to fix the git command being executed, but then I actually get no results. Still investigating...

@abo-abo
Copy link
Owner

abo-abo commented Aug 30, 2017

@noorul This is expected and is a feature:

- input `def test` means: search for `def.*test`
- input `def  test` means: search for `def test`
- input `def   test` means: search for `def  test`
- etc.

@dgchurchill Try to customize counsel-git-grep-cmd-default. Windows has problems when single quotes get passed in a command.

@dgchurchill
Copy link

Thanks @abo-abo. Setting counsel-git-grep-cmd-default to "git --no-pager grep --full-name -n --no-color -i -e \"%s\"" solved my problem. Apologies for hijacking this thread when my issue turned out to be unrelated.

@noorul
Copy link
Author

noorul commented Aug 30, 2017

@abo-abo def test_ worked! Thank you! Closing this!

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

No branches or pull requests

3 participants