about summary refs log tree commit diff
diff options
context:
space:
mode:
authorPiraty <piraty1@inbox.ru>2023-10-03 00:13:45 +0200
committerLeah Neukirchen <leah@vuxu.org>2023-10-04 14:47:21 +0200
commitf383da4a456ad64cf0a2f26f0f1a98933064cc8e (patch)
tree83d3187246fba2eeb8c0ce1b558fb5b8020fe2ed
parent19afa591ea54ff21b4b44da032895080721b8a2f (diff)
downloadxtools-f383da4a456ad64cf0a2f26f0f1a98933064cc8e.tar.gz
xtools-f383da4a456ad64cf0a2f26f0f1a98933064cc8e.tar.xz
xtools-f383da4a456ad64cf0a2f26f0f1a98933064cc8e.zip
xlocate: pass -e flag to git grep
5edebea ("xlocate: don't mark anything starting with a hyphen as ...")
added `--` so passing useful options like `--ignore-case` became
impossible.

429db43 ("xlocate: add ability to pass certain flags to git grep") made
an attempt to fix this by using a whitelist, but didn't fix the
leading-dash usecase.

If searching for pattern starting with dash, use

    xlocate -e '-foo'

This reverts commit 5edebea0a738117dde41077cd23756e79f4417e7
-rwxr-xr-xxlocate5
1 files changed, 3 insertions, 2 deletions
diff --git a/xlocate b/xlocate
index ee4d33f..5892f55 100755
--- a/xlocate
+++ b/xlocate
@@ -72,11 +72,12 @@ usage() {
 	echo "Usage: xlocate [-g | -S | [-EFGPiw] PATTERN]" >&2
 }
 
-while getopts gSEFGPiwh flag; do
+while getopts gSEFGPiwe:h flag; do
 	case $flag in
 		g) UPDATE=1 ;;
 		S) SYNC=1 ;;
 		[EFGPiw]) GREP_FLAGS="$GREP_FLAGS -$flag" ;;
+		e) GREP_FLAGS="$GREP_FLAGS -e $OPTARG" ;;
 		h) usage; exit 0 ;;
 		?) usage; exit 1 ;;
 	esac
@@ -105,7 +106,7 @@ if [ -d "$XLOCATE_GIT" ]; then
 			echo "xlocate: database outdated, please run xlocate -g." >&2
 		fi
 	fi
-	$GIT_CMD -c grep.lineNumber=false -c grep.column=false --git-dir="$XLOCATE_GIT" grep $GREP_FLAGS -- "$@" @ |
+	$GIT_CMD -c grep.lineNumber=false -c grep.column=false --git-dir="$XLOCATE_GIT" grep $GREP_FLAGS "$@" @ |
 		sed 's/^@://' | $COLUMN | grep .
 else
 	echo "xlocate: database not found, please use xlocate -S." >&2