Skip to content

Instantly share code, notes, and snippets.

@hidsh
Created April 10, 2013 11:00
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save hidsh/5353679 to your computer and use it in GitHub Desktop.
Save hidsh/5353679 to your computer and use it in GitHub Desktop.
Yet Another Alternative to 'grep find' using mdfind(a.k.a. Spotlight) on Mac OS X
#!/bin/sh
#
# g - Yet Another Alternative to 'grep find' using mdfind(a.k.a. Spotlight) on Mac OS X
#
# usage:
# $g hoge
# $g hoge dir
USAGE="usage:\n\
\$g hoge\n\
\$g hoge dir"
if [ $# -lt 1 ] || [ $# -gt 2 ]; then
echo $USAGE
exit 0
fi
WORD=$1
if [ $# -lt 2 ]; then
DIR="."
else
DIR=$2
fi
mdfind -0 -onlyin $DIR $WORD | xargs -0 grep -Hin $WORD
exit 0
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment