Comments (12)
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.
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.
Dang, nice find. I was starring only at print.c.
from the_silver_searcher.
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.
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.
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.
ARGH GitHub! Stop auto-closing this issue.
from the_silver_searcher.
No, I wanted to get a listing of every file in my folder (and subfolders).
from the_silver_searcher.
So a couple of things are happening here.
- 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.
- You're not specifying a path to search in, so ag assumes you want to search the current directory.
- 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.
- 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.
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.
Problem is non existent these days.
from the_silver_searcher.
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)
- Running any search within a specific directory opens a file in that directory in Visual Studio
- Anyone want to help with a friendly fork of this project? HOT 6
- --make file type...
- Travis CI badge is broken
- Compilation stoped on qualifier from pointer target type [-Wcast-qual] HOT 1
- "bus error" on Mac OS with specific test file and regex HOT 1
- ag not finding accent letters in case insensitive search explicitly with -i option
- If the file doesn't exist, skip search instead of throwing errors
- wrong output on osx default terminal
- Confused about flag `--print-long-lines`: long lines seem to be printed by default? But can't turn that behavior *off* or modify it? (like `--print-long-lines=false` or `--print-long-lines=200` or something?)
- 2.2.0: test suite uses cram which is no longer maintained
- Add per-directory .gitignore support
- ignore patterns should not directory below their source file
- ag incorrectly parses [.][^.]*$
- feat: include OSC8 escape codes in output
- memory leak in function 'parse_options' HOT 1
- ag does not work on tmpfs/cgroup filesystem
- Entries in .gitignore are applied to the wrong base directory
- Bash completion script is broken with bash-completion v2.12.0 HOT 1
- Missing `S_ISSOCK` for stdin check HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from the_silver_searcher.