Two more complicated shell functions. I use them often when searching stuff in source code or config files.
FFind() {
if [ -n "$1" ] ; then
if [ -n "$2" ] ; then
local testVar="$1"
shift
find . -type f \
-and '(' -not -path '*.git*' ')' \
-and '(' -not -path '*.svn*' ')' \
-and '(' -not -path '*.hg*' ')' \
-and '(' "$@" ')' \
-exec grep --color=always -I -i -F -H -n "${testVar}" {} ';'
else
find . -type f \
-and '(' -not -path '*.git*' ')' \
-and '(' -not -path '*.svn*' ')' \
-and '(' -not -path '*.hg*' ')' \
-exec grep --color=always -I -i -F -H -n "$1" {} ';'
fi
fi
}
EFind() {
if [ -n "$1" ] ; then
if [ -n "$2" ] ; then
local testVar="$1"
shift
find . -type f \
-and '(' -not -path '*.git*' ')' \
-and '(' -not -path '*.svn*' ')' \
-and '(' -not -path '*.hg*' ')' \
-and '(' "$@" ')' \
-exec grep --color=always -I -i -E -H -n -m 1 "${testVar}" {} ';'
else
find . -type f \
-and '(' -not -path '*.git*' ')' \
-and '(' -not -path '*.svn*' ')' \
-and '(' -not -path '*.hg*' ')' \
-exec grep --color=always -I -i -E -H -n -m 1 "$1" {} ';'
fi
fi
}
Usage:
FFind elephant
Recursively searches all text files in the current directory for the string elehant. Ignores files created by Subverion, git or mercurial. Ignores binary files.
FFind 'ele.*phant' -name '*.c' -or -name '*.h'
Recursively searches all c code files in the current directory for the string 'ele.*hant' (no regular expression matching). Ignores files created by Subverion, git or mercurial.
EFind 'mo*use' -name '*.java'
Recursively searches all java code files in the current directory for the string muse or mouse or moouse or .... Ignores files created by Subverion, git or mercurial.
Tested with bash and zsh.
mysql
(anyone else on the server could see it!), put the username and password in a ~/.my.cnf file, and simply specify-up
. MySQL tools will pick those credentials up automatically, read mysql(1) for more info.