a better name.
[feisty_meow.git] / scripts / text / search_text.sh
diff --git a/scripts/text/search_text.sh b/scripts/text/search_text.sh
new file mode 100644 (file)
index 0000000..e88c58d
--- /dev/null
@@ -0,0 +1,49 @@
+#!/bin/bash
+seek="$1"; shift
+if [ -z "$seek" ]; then
+  echo This script needs a pattern to look for in the current directory.
+  echo All non-binary files here and in subdirectories will be searched for the
+  echo pattern.
+  echo A directory can be passed as an optional second parameter, which will
+  echo cause the search to occur in that directory instead.
+  exit 1
+fi
+#hmmm: might be nice to support multiple directories...
+#      just need to pass them to find as an array maybe?
+dir="$1"; shift
+if [ -z "$dir" ]; then
+  dir=.
+fi
+
+#hmmm: we need to encode this useful logic as a list of binary file endings.
+find "$dir" -type f \( -iname "*" \
+  ! -iname "*~" \
+  ! -iname "*.bin" \
+  ! -iname "*.bz2" \
+  ! -iname "*.class" \
+  ! -iname "*.dll" \
+  ! -iname "*.deb" \
+  ! -iname "*.dmg" \
+  ! -iname "*.exe" \
+  ! -iname "entries" \
+  ! -iname "*.git" \
+  ! -iname "*.gz" \
+  ! -iname "*.iar" \
+  ! -iname "*.jar" \
+  ! -iname "*.lib" \
+  ! -iname "*.ncb" \
+  ! -iname "*.oar" \
+  ! -iname "*.obj" \
+  ! -iname "*.pch" \
+  ! -iname "*.png" \
+  ! -iname "*.snarf" \
+  ! -iname "*.so" \
+  ! -iname "*.so.2" \
+  ! -iname "*.svn" \
+  ! -iname "*.svn-base" \
+  ! -iname "*.tar" \
+  ! -iname "*.tmp" \
+  ! -iname "*.zip" \) \
+  -exec echo "\"{}\"" ';' | xargs grep -li "$seek" | grep -v "^\.[^\/]\|\/\."
+
+