Skip to content


Add option to disable reading file content to guess filetype #147

kcwu opened this Issue · 4 comments

2 participants


Suggest to add option to disable reading file header to guess filetype.
This should disable

  • test binary file
  • shebang line

Read files from NFS is slow, so I would like search files only based on filename.


Alternative solution:
Read file content only if user specify file type binary,text,ruby,perl,php,python,*sh,xml,etc.

For example, it's unnecessary to read file content for ack --cpp.


kcwu: Thanks, that makes a lot of sense.

diff --git a/ b/
index 3cf01dc..609a347 100644
--- a/
+++ b/
@@ -519,6 +519,7 @@ sub filetypes {
     # At this point, we can't tell from just the name.  Now we have to
     # open it and look inside.

+    return unless grep defined $type_wanted{$_}, qw/binary shell xml ruby perl php python/, TEXT;
     return unless -e $filename;
     # From Elliot Shank:
     #     I can't see any reason that -r would fail on these-- the ACLs look
@@ -534,6 +535,7 @@ sub filetypes {

     return 'binary' if -B $filename;
+    return (TEXT) unless grep defined $type_wanted{$_}, qw/shell xml ruby perl php python/;

     # If there's no extension, or we don't recognize it, check the shebang line
     my $fh;

This is much smarter in ack 2.

@petdance petdance closed this
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Something went wrong with that request. Please try again.