Last active
October 19, 2017 12:57
-
-
Save inodev/815d3acc2f8dc2018a38f384f09bd5fb to your computer and use it in GitHub Desktop.
findで拡張子を指定してgrepするコマンド
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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