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