Skip to content

Commit

Permalink
Merge pull request rauchg#22 from rase-/add/file-flag
Browse files Browse the repository at this point in the history
Add flag to match file name pattern
  • Loading branch information
rauchg committed Oct 31, 2014
2 parents 650f5a6 + 611a4bb commit 3c58b37
Showing 1 changed file with 16 additions and 1 deletion.
17 changes: 16 additions & 1 deletion spot.sh
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,9 @@ fi
# show matches by default
showmatches=1

# file name pattern
filename=

# line numbers shown by default
linenums=1

Expand All @@ -41,6 +44,7 @@ usage() {
-e, --exclude [dir] Exclude directory from search
-s, --sensitive Force case sensitive search.
-i, --insensitive Force case insensitive search.
-f, --file Only search file names matching the provided pattern
-C, --no-colors Force avoid colors.
-l, --filenames-only Only list filenames with matches.
-L, --no-linenums Hide line numbers.
Expand Down Expand Up @@ -80,6 +84,10 @@ while [[ "$1" =~ ^- && ! "$1" == "--" ]]; do
-i | --insensitive )
sensitive=
;;
-f | --file )
shift; ffile=$1;
filename=$ffile
;;
-C | --no-colors )
colors=
;;
Expand Down Expand Up @@ -141,8 +149,15 @@ fi
# add force colors
grepopt="$grepopt --color=always"

# find default params
findopt=

if [ $filename ]; then
findopt="$findopt -name $filename"
fi

# run search
eval "find "$dir" -type f $exclude -print0" \
eval "find "$dir" $findopt -type f $exclude -print0" \
| GREP_COLOR="1;33;40" xargs -0 grep $grepopt -e "`echo $@`" \
| sed "s/^\([^:]*:\)\(.*\)/ \\
$cyan\1$reset \\
Expand Down

0 comments on commit 3c58b37

Please sign in to comment.