Subject: | More filetypes to ignore |
Your script reminds me of a shell script of mine which does a subset of
ack: a recursive grep, but with more filetypes to ignore. It would be
nice to ignore every kind of binary file, but this is not so easy:
you have to look into a file to decide whether it's binary. Also, a
binary/invalid character in one encoding may be a valid character
in another encoding.
Here's the script:
find . -type f -a ! \( \
-regex ".*/blib/.*" \
-o -regex ".*/CVS/.*" \
-o -regex ".*/RCS/.*" \
-o -regex '.*,v$' \
-o -regex ".*/.svn/.*" \
-o -regex ".*/\\.svn/.*" \
-o -regex ".*\\.[oa]" \
-o -regex ".*~" \
-o -regex ".*/#[^#]*#" \
-o -regex ".*\\.gz" \
-o -regex ".*\\.bz2" \
-o -regex ".*\\.bak" \
-o -regex ".*\\.tgz" \
-o -regex ".*\\.tbz" \
-o -regex ".*\\.gif" \
-o -regex ".*\\.jpe?g" \
-o -regex ".*\\.png" \
-o -regex ".*\\.elc" \
-o -name ".#*" \
-o -name "Makefile.old" \
\) -print0 | xargs -0 grep "$@"
Explanation:
.*,v$ ignores RCS files which are created outside of an RCS directory.
.*/#[^#]*#" ignores emacs autosave files.
.*~ ignores emacs backup files.
.*\\.elc are compiled emacs lisp files.
Regards,
Slaven