Skip to content
This repository

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

kcwu opened this Issue November 27, 2010 · 4 comments

2 participants

Kuang-che Wu Andy Lester
Kuang-che Wu

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.

Kuang-che Wu

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.

Andy Lester

kcwu: Thanks, that makes a lot of sense.

Kuang-che Wu
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;
Andy Lester

This is much smarter in ack 2.

Andy Lester petdance closed this April 26, 2013
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.