corrected erroneous return type in test hash table. made search_text skip binary...
[feisty_meow.git] / scripts / text / search_text.sh
1 #!/bin/bash
2 seek="$1"; shift
3 if [ -z "$seek" ]; then
4   echo This script needs a pattern to look for in the current directory.
5   echo All non-binary files here and in subdirectories will be searched for the
6   echo pattern.
7   echo A directory can be passed as an optional second parameter, which will
8   echo cause the search to occur in that directory instead.
9   exit 1
10 fi
11 #hmmm: might be nice to support multiple directories...
12 #      just need to pass them to find as an array maybe?
13 dir="$1"; shift
14 if [ -z "$dir" ]; then
15   dir=.
16 fi
17
18 #hmmm: we need to encode this useful logic as a list of binary file endings.
19 find "$dir" -type f \( -iname "*" \
20   ! -iname "*~" \
21   ! -iname "*.bin" \
22   ! -iname "*.bz2" \
23   ! -iname "*.class" \
24   ! -iname "*.dll" \
25   ! -iname "*.deb" \
26   ! -iname "*.dmg" \
27   ! -iname "*.doc" \
28   ! -iname "*.docx" \
29   ! -iname "*.exe" \
30   ! -iname "entries" \
31   ! -iname "*.git" \
32   ! -iname "*.gif" \
33   ! -iname "*.gz" \
34   ! -iname "*.iar" \
35   ! -iname "*.jar" \
36   ! -iname "*.jpg" \
37   ! -iname "*.lib" \
38   ! -iname "*.ncb" \
39   ! -iname "*.oar" \
40   ! -iname "*.obj" \
41   ! -iname "*.pch" \
42   ! -iname "*.png" \
43   ! -iname "*.snarf" \
44   ! -iname "*.so" \
45   ! -iname "*.so.2" \
46   ! -iname "*.svn" \
47   ! -iname "*.svn-base" \
48   ! -iname "*.tar" \
49   ! -iname "*.tmp" \
50   ! -iname "*.xls" \
51   ! -iname "*.xlsx" \
52   ! -iname "*.zip" \) \
53   -exec echo "\"{}\"" ';' | xargs grep -li --binary-files=without-match -- "$seek" | grep -v "^\.[^\/]\|\/\."
54
55 # first grep looks in every valid file for the pattern requested.
56 # second grep strains out dot files.
57 #hmmm: why are we doing that second step?
58
59
60