Skip to content

Commit

Permalink
Fix all ShellCheck warnings
Browse files Browse the repository at this point in the history
Revert removal of color variable check for grep color option so -C works as advertised
  • Loading branch information
Xaekai committed Dec 3, 2014
1 parent 3c58b37 commit 07b9334
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 15 deletions.
5 changes: 5 additions & 0 deletions History.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,9 @@

0.2.1 / 2014-12-03
==================

* Fix all ShellCheck warnings [Xaekai]

0.2.0 / 2014-10-30
==================

Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "spot",
"version": "0.2.0",
"version": "0.2.1",
"description": "file grep/search utility with good defaults",
"bin": {
"spot": "./spot.sh"
Expand Down
30 changes: 16 additions & 14 deletions spot.sh
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#!/usr/bin/env bash

version="0.2.0"
version="0.2.1"

# search directory defaults to current
dir=.
Expand Down Expand Up @@ -28,8 +28,8 @@ filename=
linenums=1

# ansi colors
cyan=`echo -e '\033[96m'`
reset=`echo -e '\033[39m'`
cyan=$(echo -e '\033[96m')
reset=$(echo -e '\033[39m')

# max line length
mline=500
Expand Down Expand Up @@ -112,13 +112,13 @@ if [[ "$1" == "--" ]]; then shift; fi
# check for directory as first parameter
if [[ "$1" =~ / ]]; then
if [ -d "$1" ]; then
dir=`echo $1 | sed "s/\/$//"`
dir=${1/%\//}
shift
fi
fi

# check for empty search
if [[ "" = "$@" ]]; then
if [ -z "$@" ]; then
echo "(no search term. \`spot -h\` for usage)"
exit 1
fi
Expand All @@ -129,40 +129,42 @@ if [[ "$@" =~ [A-Z] ]]; then
fi

# grep default params
grepopt="--binary-files=without-match --devices=skip"
grepopt=( --binary-files=without-match --devices=skip )

# add case insensitive search
if [ ! $sensitive ]; then
grepopt="$grepopt --ignore-case"
grepopt[${#grepopt[*]}]="--ignore-case"
fi

# add filename only options
if [ ! $showmatches ]; then
grepopt="$grepopt -l"
grepopt[${#grepopt[*]}]="-l"
fi

# add line number options
if [ $linenums ]; then
grepopt="$grepopt -n"
grepopt[${#grepopt[*]}]="-n"
fi

# add force colors
grepopt="$grepopt --color=always"
if [ $colors ]; then
grepopt[${#grepopt[*]}]="--color=always"
fi

# find default params
findopt=

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

# run search
eval "find "$dir" $findopt -type f $exclude -print0" \
| GREP_COLOR="1;33;40" xargs -0 grep $grepopt -e "`echo $@`" \
eval "find $dir $findopt -type f $exclude -print0" \
| GREP_COLOR="1;33;40" xargs -0 grep "${grepopt[@]}" -e "$@" \
| sed "s/^\([^:]*:\)\(.*\)/ \\
$cyan\1$reset \\
\2 /" \
| awk -v linenums=$linenums -v reset=`tput sgr0` -v colors=$colors -v mline=$mline '{
| awk -v linenums=$linenums -v reset="$(tput sgr0)" -v colors=$colors -v mline=$mline '{
if (length($0) > mline) {
# Get line number string
i = index($0, ":")
Expand Down

0 comments on commit 07b9334

Please sign in to comment.