description of default file choice logic for ack

47 views
Skip to first unread message

Sitaram Chamarty

unread,
Feb 14, 2009, 8:14:28 PM2/14/09
to ack-...@googlegroups.com
[changed subject line]

On Wed, Feb 11, 2009 at 2:46 PM, Daniel Wagner <daniel...@gmail.com> wrote:

> On Tue Feb 10, 11:04 AM, Andy Lester <a...@petdance.com> wrote:
> There's really no English that explains how it works.

Well, maybe some should be written. ;-)

Absolutely; I don't see this as a limitation of the English language ;-)

I get the feeling, from the list, that I have been caught off-guard by ack more than anyone else on this list (at least I'm the only one who nearly lost data once because of ack; see thread around July last year, subject line 'ack recurses into $PWD when stdin is a pipe at EOF' or some such words, which ended with Bill Riker suggesting we use '-p' to detect pipes and all that).

So I've spent a bit of time on this.

So I wrote up all this, again as I said because my use case is apparently not typical.  I'm not really a dev anymore, and my files are not neatly laid out with extensions.

Anyway, it would be nice if Andy would confirm/correct this, maybe clean it up, and then put it up somewhere on the ack website, as well as (or at least in) the section that says 'when to use grep' in the manpage.

If not, it's available on the list anyway and hopefully others can find it by googling if they are ever in this situation.

-------------------------------------------------

The following description applies only to the default usage (no .ackrc, no special flags, and 0 or more paths to search).  These bullets are to be read sequentially, stopping when the file is either selected or rejected at any stage.

 - if paths are given, ack recurses those paths instead of $PWD
 - for each file found, if it was an explicit command line argument, it is selected.
   -- unless the file is a special file in /proc etc., which returns '0' when asked for its size, in which case it is rejected
 - if the filename starts with a period, it is rejected
 - if the filename ends in .bak or ~, it is rejected.  Vim's swap files (but only *.swp, not *.swo, *.swn, etc - this is easy to fix by the way) and core files are also rejected
 - if the filename is 'makefile' or 'rakefile' (case-insensitive), it is selected
 - if it has one of the known extensions (found by 'ack --help type') then it is selected
 - if it does not have a known extension, and it is a binary file (using perl's -B operator), it is rejected
 - if the hash-bang line indicates it is perl, php, python, ruby, bash, sh, csh, tcsh, ksh, or zsh, it is selected.  (It does not check other possible hash-bang lines (such as '#!/usr/bin/make' for instance, or tcl -- this also is an easy consistency fix.  'wish' is also a likely candidate to add to this stage, as is /usr/bin/env)
 - if it finds the text '<?xml' in the first line, it selects the file
 - if the file hasn't been selected yet, it is rejected

-------------------------------------------------

Hope this helps.  I haven't gone into the variations if you use --all, or --text, etc.

Regards,

Sitaram

Andy Lester

unread,
Feb 14, 2009, 8:19:02 PM2/14/09
to ack-...@googlegroups.com

On Feb 14, 2009, at 7:14 PM, Sitaram Chamarty wrote:

> The following description applies only to the default usage
> (no .ackrc, no special flags, and 0 or more paths to search). These
> bullets are to be read sequentially, stopping when the file is
> either selected or rejected at any stage.


This looks pretty accurate. Thanks for writing this up.

--
Andy Lester => an...@petdance.com => www.petdance.com => AIM:petdance


Sitaram Chamarty

unread,
Feb 14, 2009, 8:23:47 PM2/14/09
to ack-...@googlegroups.com
On Sun, Feb 15, 2009 at 6:49 AM, Andy Lester <an...@petdance.com> wrote:


On Feb 14, 2009, at 7:14 PM, Sitaram Chamarty wrote:

> The following description applies only to the default usage
> (no .ackrc, no special flags, and 0 or more paths to search).  These
> bullets are to be read sequentially, stopping when the file is
> either selected or rejected at any stage.


This looks pretty accurate.  Thanks for writing this up.


Good to hear confirmation from you.  I assume you'll put up some version of it on the website or in the man page for future such questions.

Regards,

Sitaram

Andy Lester

unread,
Feb 14, 2009, 8:26:47 PM2/14/09
to ack-...@googlegroups.com

On Feb 14, 2009, at 7:23 PM, Sitaram Chamarty wrote:

> Good to hear confirmation from you. I assume you'll put up some
> version of it on the website or in the man page for future such
> questions.


Sure, in my copious free time. :-)

Reply all
Reply to author
Forward
0 new messages