Usage: zf PATTERN [DIR]
Example: zf foo app/
Paste this somewhere. I use it in /usr/local/bin
. Remeber to chmod +x /usr/local/bin/zf
.
if [ -z "$1" ]
then
echo "usage: zf PATTERN [DIR]"
echo "example: zf foo app/"
exit 1
fi
regex=""
for (( i = 0; i < ${#1}; i++ )); do
char=${1:$i:1}
char="$char[^\n]*?"
regex="$regex$char"
done
breakat=$(( ${#regex} - 7 ))
regex=${regex:0:breakat}
path=$2
if [ -z "$2" ]
then
path="."
fi
grep -ERni --color=always "$regex" "$path"