Skip to content

Instantly share code, notes, and snippets.

@inodev
Last active October 19, 2017 12:57
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save inodev/815d3acc2f8dc2018a38f384f09bd5fb to your computer and use it in GitHub Desktop.
Save inodev/815d3acc2f8dc2018a38f384f09bd5fb to your computer and use it in GitHub Desktop.
findで拡張子を指定してgrepするコマンド
#!/bin/sh
DEFAULT_FILES="html erb slim haml css scss sass js coffee rb rake yml"
usage_msg() {
echo "usage: `basename $0` grep_text [find_files]"
echo "(example) `basename $0` current_user erb slim"
}
### error check & init
case $# in
0 ) # param none
usage_msg
exit 1
;;
1 ) # set default params
set -- ${1} ${DEFAULT_FILES}
;;
* )
;;
esac
### build params
TARGET_TEXT=$1
extensions="-type f -name *.${2}"
shift
while [ "$2" != "" ]; do
extensions="${extensions} -o -type f -name *.${2}"
shift
done
### execute
find . ${extensions} | xargs egrep -n --color=always ${TARGET_TEXT}
exit 0
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment