Created
April 2, 2019 16:13
-
-
Save jayers99/c14dc08e005b9e076abfb05554a5eac4 to your computer and use it in GitHub Desktop.
repo grep search code
This file contains hidden or 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/bash | |
# | |
# search repo files for some string | |
# | |
# defaults | |
# current repo root directory | |
# if not repo then current dir | |
# all file types not in exclude list | |
# irnP options | |
# options | |
# -c for current directory not repo root | |
# -f = just file path = | |
# -m = just matching text = | |
# coming soon | |
# -t for file type list | |
# terraform | |
# go | |
# sh (advanced shebang) | |
# set all the defaults | |
GREP='grep' | |
OPTIONS='irnP --color' | |
INCLUDE_EXT=(sh sed awk snippets bash zsh ksh tf tfvars py go) | |
INCLUDE_FILES='' | |
EXCLUDE_EXT=(tmp log md json tfstate* jpg pdf) | |
EXCLUDE_FILES='' | |
EXCLUDE_DIRS='--exclude-dir=.terraform --exclude-dir=.git' | |
SEARCH_DIR=$(repodir.sh) | |
# change as per options | |
while [ -n "$1" ]; do | |
case "$1" in | |
-c) | |
SEARCH_DIR=$PWD ;; | |
-f) | |
OPTIONS='irlP' ;; | |
-m) | |
OPTIONS='irPoh --no-filename' ;; | |
-l) | |
OPTIONS='irP --color --no-filename' ;; | |
-t) | |
INCLUDE_EXT=($2); shift ;; | |
*) | |
break ;; | |
esac | |
shift | |
done | |
#total=1 | |
#for param in "$@"; do | |
# echo "#$total: $param" | |
# total=$(($total + 1)) | |
#done | |
for i in ${INCLUDE_EXT[*]}; do INCLUDE_FILES+="--include=\*.$i " ; done | |
for i in ${EXCLUDE_EXT[*]}; do EXCLUDE_FILES+="--exclude=\*.$i " ; done | |
SEARCH=$1 | |
CMD="$GREP -$OPTIONS $INCLUDE_FILES $EXCLUDE_FILES $EXCLUDE_DIRS '$SEARCH' $SEARCH_DIR" | |
#echo $CMD | |
eval $CMD |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment