about summary refs log tree commit diff
path: root/xlocate
diff options
context:
space:
mode:
authorclassabbyamp <void@placeviolette.net>2023-03-22 05:55:11 -0400
committerLeah Neukirchen <leah@vuxu.org>2023-08-05 19:25:23 +0200
commit429db434a76e2931985d347ad60b7e37debbdaee (patch)
tree41549b2863f8458639e742628b26f00bbbf037b0 /xlocate
parent2ca7afbfc5e003bc9812f32c3129a580706bb7a3 (diff)
downloadxtools-429db434a76e2931985d347ad60b7e37debbdaee.tar.gz
xtools-429db434a76e2931985d347ad60b7e37debbdaee.tar.xz
xtools-429db434a76e2931985d347ad60b7e37debbdaee.zip
xlocate: add ability to pass certain flags to git grep
implemented what I thought would be useful and made sense, namely:

- `-E, --extended-regexp`
- `-F, --fixed-strings`
- `-G, --basic-regexp`
- `-P, --perl-regexp`
- `-i, --ignore-case`
- `-w, --word-regexp`

This will also allow for someone with `grep.patternType` or
`grep.extendedRegexp` set in git's config to change the pattern type.
Diffstat (limited to 'xlocate')
-rwxr-xr-xxlocate34
1 files changed, 23 insertions, 11 deletions
diff --git a/xlocate b/xlocate
index 4909d00..ee4d33f 100755
--- a/xlocate
+++ b/xlocate
@@ -1,5 +1,5 @@
 #!/bin/sh
-# xlocate [-g | -S | PATTERN] - locate files in all XBPS packages
+# xlocate [-g | -S | [-EFGPiw] PATTERN] - locate files in all XBPS packages
 
 : ${XDG_CACHE_HOME:=~/.cache}
 : ${XDG_CONFIG_HOME:=~/.config}
@@ -68,17 +68,29 @@ xsyncgit() {
 	$GIT_CMD -C "$XLOCATE_GIT" fetch -u -f "$XLOCATE_REPO" master:master
 }
 
-case "$1" in
--g)
+usage() {
+	echo "Usage: xlocate [-g | -S | [-EFGPiw] PATTERN]" >&2
+}
+
+while getopts gSEFGPiwh flag; do
+	case $flag in
+		g) UPDATE=1 ;;
+		S) SYNC=1 ;;
+		[EFGPiw]) GREP_FLAGS="$GREP_FLAGS -$flag" ;;
+		h) usage; exit 0 ;;
+		?) usage; exit 1 ;;
+	esac
+done
+
+shift $(( OPTIND - 1 ))
+
+if [ -n "$UPDATE" ]; then
 	xupdategit
-	exit $?;;
--S)
+	exit $?
+elif [ -n "$SYNC" ]; then
 	xsyncgit
-	exit $?;;
-'')
-	echo "Usage: xlocate [-g | -S | PATTERN]" >&2
-	exit 1;;
-esac
+	exit $?
+fi
 
 if [ -d "$XLOCATE_GIT" ]; then
 	if [ -f "$XLOCATE_GIT/refs/heads/master" ]; then
@@ -93,7 +105,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 -- "$@" @ |
+	$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