Re: Top 10 reasons to start using ack
by diotalevi (Canon) on Nov 30, 2006 at 05:21 UTC
|
I wrote diotalevi's grep. It's one distinguishing feature is automatically looking inside tarballs and zip files. I find that's really common for me. It does a dirt simple look at the file extension and opens .tgz/.zip/.whatever using the streaming abilities of archive extraction programs. The code isn't sexy and it isn't even good but it does do a pretty good enough job. It'd be possible to do a much better job given a few minutes and the interest. I'd use ack immediately if it got this feature.
sub open_file_harder {
my ($filename) = @_;
return if not defined $filename;
if ( my ($extension) = $filename =~ /(\.[^.]+)\z/mx ) {
my @readers = (
[ qr/\.t(?:ar\.)?gz\z/ => qw( gzcat ), $filename ],
[ qr/\.zip\z/, => qw( unzip -p ), $filename ],
[ qr/\.Z\z/ => qw( zcat ), $filename ],
[ qr/\.gz\z/ => qw( gzcat ), $filename ],
[ qr/\.bz2\z/ => qw( bzcat ), $filename ],
);
for my $reader (@readers) {
my ( $pattern, @command ) = @{$reader};
if ( $extension =~ $pattern ) {
open3( undef, my $fh, undef, @command );
return $fh;
}
}
}
open my $fh, '<', $filename
or die "Couldn't open $filename: $!";
return $fh;
}
| [reply] [d/l] |
|
A couple of thoughts:
* I wouldn't have it on by default. It would only be via the -A,--archive switch, for example.
* How would I show the resultant filename? If the file is in a tarball, what do I show for the filename?
| [reply] |
|
| [reply] |
|
|
|
Re: Top 10 reasons to start using ack
by Ovid (Cardinal) on Nov 30, 2006 at 13:42 UTC
|
I love ack, but I'd strongly recommend .ackrc support. For example, one project I work on has non-standard extensions for Perl files, so ack doesn't recognize them as being Perl. It would be nice to have an .ackrc so that I can provide those extra extensions to add on to ack file recognition or to specify default switches. Of course, this would require an extra switch to ack to ensure that the .ackrc is not read, if necessary.
It would be a nice feature for prove, also. The vast majority of time I just type prove -l t. For prove, you could ignore the .proverc if you have any arguments. For ack, you could ignore the .ackrc if you have more than one argument.
| [reply] |
|
ack is really nice; just this morning I've started using it in favor of my bash wrappers around grep. I agree with Ovid, though -- .ackrc support would be super-keen. ACK_SWITCHES is good, but say I want a different set of options per project?
Minor quibble, though. Nice work, petdance.
| [reply] |
|
Really what you're asking for is not .ackrc support, but support for specifying filetypes.
| [reply] |
Re: Top 10 reasons to start using ack
by duelafn (Parson) on Nov 30, 2006 at 16:01 UTC
|
I'm not sure that completely ignoring unrecognised text files is the best form of DWIM. It took me several searches to realize that ack does not recognise TeX files. I suspect that this would mean that extensionless plain text files would not be searched since they have no #! line. Having to specify the --all option to search these files takes away some of the fun since then backup (~) files are included then. Perhaps a --text option (anything matching -T that is not a backup file) as a counterpart to the --binary option would be nice.
| [reply] |
Re: Top 10 reasons to start using ack
by jmcnamara (Monsignor) on Nov 30, 2006 at 09:07 UTC
|
I've been using ack for a while on Linux and Solaris and it is genuinely very useful. Well done.
--
John.
| [reply] |
Re: Top 10 reasons to start using ack
by parv (Parson) on Dec 01, 2006 at 05:28 UTC
|
You gave me a few ideas that I should include in my own file searching program, namely ...
- by default ignore CVS & .svn directories (i am tired of filtering find(1) output) (1);
- specify types of files to search (3).
Thanks much.
BTW, I got 403 error when I tried to access http://petdance.com/ack.
| [reply] |
|
| [reply] |
Re: Top 10 reasons to start using ack
by Cody Pendant (Prior) on Dec 06, 2006 at 05:49 UTC
|
OK, I have to ask ... why is it called "ack"?
($_='kkvvttuu bbooppuuiiffss qqffssmm iibbddllffss')
=~y~b-v~a-z~s; print
| [reply] |
|
Because it's short and pronouncable.
| [reply] |
|
Darn. I was hoping for something more creative involving Bill the Cat and Bloom County, even if it's made up...
Update: You know, I totally forgot about --thppttt
| [reply] |
|