batgrep: Add support for '--'

This commit is contained in:
Ethan P 2021-08-21 15:48:14 -07:00
parent 82ac5c4391
commit 33e0c168e0
No known key found for this signature in database
GPG Key ID: 6963FD04F6CF35EA

View File

@ -130,6 +130,9 @@ while shiftopt; do
fi
} ;;
# --
--) getargs -a FILES; break ;;
# ???
-*) {
printc "%{RED}%s: unknown option '%s'%{CLEAR}\n" "$PROGRAM" "$OPT" 1>&2
@ -137,17 +140,15 @@ while shiftopt; do
} ;;
# Search
*) {
if [ -z "$PATTERN" ]; then
PATTERN="$OPT"
else
FILES+=("$OPT")
fi
} ;;
*) FILES+=("$OPT") ;;
esac
done
# Use the first file as a pattern.
PATTERN="${FILES[0]}"
FILES=("${FILES[@]:1}")
if [[ -z "$PATTERN" ]]; then
print_error "no pattern provided"
exit 1
@ -229,6 +230,7 @@ main() {
"${RG_ARGS[@]}" \
--context 0 \
--sort path \
-- \
"$PATTERN" \
"${FILES[@]}" \
)