GithubHelp home page GithubHelp logo

Comments (12)

sjl avatar sjl commented on May 18, 2024 2

This just bit me too, trying to run ag from a system() call in Vim. Magical behavior that depends on context instead of arguments is fun.

from the_silver_searcher.

rphillips avatar rphillips commented on May 18, 2024

Hmm .The bug is on this line https://github.com/ggreer/the_silver_searcher/blob/master/src/options.c#L153

commenting it out gets the node app to work. Not sure what the right fix is for this case.

from the_silver_searcher.

gjtorikian avatar gjtorikian commented on May 18, 2024

Dang, nice find. I was starring only at print.c.

from the_silver_searcher.

ggreer avatar ggreer commented on May 18, 2024

Yeah, this is by design. Ag assumes that if stdin isn't a tty, it should search stdin. I'm pretty sure Ack does the same thing.

If you don't like how --ackmate messes up the formatting, use --parallel or --search-files. I added these to fix #33.

I'm thinking that if a query and a path are specified, I should default to searching files instead of stdin, regardless of whether stdin is a tty or not.

from the_silver_searcher.

ggreer avatar ggreer commented on May 18, 2024

It looks like ack behaves similarly to ag. I forked your gist to get the path to ag working for me and simplify the args a little. Replacing ack with ag in that gist causes this:

% node spawn.js
stderr: ack: Ignoring 1 argument on the command-line while acting as a filter.

^C%                                     

Adding -l to the params gets slightly different behavior:

% node spawn.js
stderr: ack: Can't use -l when acting as a filter.

child process exited with code 255

from the_silver_searcher.

ggreer avatar ggreer commented on May 18, 2024

Also, I'm not sure you had the parameters correct in your gist. Did you want to search for "." in files?

from the_silver_searcher.

ggreer avatar ggreer commented on May 18, 2024

ARGH GitHub! Stop auto-closing this issue.

from the_silver_searcher.

gjtorikian avatar gjtorikian commented on May 18, 2024

No, I wanted to get a listing of every file in my folder (and subfolders).

from the_silver_searcher.

ggreer avatar ggreer commented on May 18, 2024

So a couple of things are happening here.

  1. You're telling ag to search for the pattern ".", which should match any file with at least one character in it. It will not match zero-byte files.
  2. You're not specifying a path to search in, so ag assumes you want to search the current directory.
  3. But you're calling ag from a script, so stdin is not a tty. Since no path is specified, ag assumes you want to search stdin instead of the current directory. Ack behaves this way as well.
  4. But you're telling ag to print out just the filenames that contain matches. This only makes sense if you're searching a path, not stdin.

There are a lot of flags like -l that imply "I want to search files, not stdin." I'm not sure I want to silently search files instead of stdin if any of those flags are passed and stdin is not a tty. Either way, I can definitely see users accidentally triggering unintended behavior. I think the best course of action is to die with an error message. If users want to spawn a child process that searches a path instead of stdin, they'll have to specify the path.

Thoughts?

Also, if you just want to print the files in a directory, why not use find .?

from the_silver_searcher.

gjtorikian avatar gjtorikian commented on May 18, 2024

You're telling ag to search for the pattern ".", which should match any file with at least one character in it. It will not match zero-byte files.

That's what I want.

Also, if you just want to print the files in a directory, why not use find .?

Because I'm lazy.

Well, the real reason is that there are slight inconsistencies between BSD find and GNU find, and in the larger context I'm tired of keeping a special logic switch between the two. (For regexps, BSD uses -E, while GNU uses -regextype, to distinguish between extended/modern REs over basic ones.) Plus I get to rely on using my *ignore files instead of constructing convoluted ! -regex rules for ignores (not shown--I actually am ignoring files in subdirs.)

Thoughts?

I agree with erring with a message. Given all of the above, plus the change to options.c, I was able to achieve what I wanted. My issue was with there not being any context whatsoever as to what was going on, but the explanation makes sense to me. I think an alternative of creating a new flag just to support this is overkill.

from the_silver_searcher.

gjtorikian avatar gjtorikian commented on May 18, 2024

Problem is non existent these days.

from the_silver_searcher.

teamon avatar teamon commented on May 18, 2024

I just got bitten by this when using:

while read -r x; do
  ag "..."
done <<< "..."

A message to stderr "searching stdin" would be nice to have.

from the_silver_searcher.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.