batgrep: Add simple parsing of RIPGREP_CONFIG_PATH.

This commit is contained in:
Ethan P 2020-10-02 20:09:00 -07:00
parent dc50f28480
commit 5f5023d056
No known key found for this signature in database
GPG Key ID: 6963FD04F6CF35EA

View File

@ -45,6 +45,46 @@ if version_compare "$(bat_version)" -gt "0.12"; then
OPT_SNIP=",snip"
fi
# Parse RIPGREP_CONFIG_PATH.
if [[ -n "$RIPGREP_CONFIG_PATH" && -e "$RIPGREP_CONFIG_PATH" ]]; then
# shellcheck disable=SC2013
for arg in $(cat "$RIPGREP_CONFIG_PATH"); do
case "$arg" in
--context=*)
val="${arg:10}"
OPT_CONTEXT_BEFORE="$val"
OPT_CONTEXT_AFTER="$val"
;;
--before-context=*)
val="${arg:17}"
OPT_CONTEXT_BEFORE="$val"
;;
--after-context=*)
val="${arg:16}"
OPT_CONTEXT_AFTER="$val"
;;
-C*)
val="${arg:2}"
OPT_CONTEXT_BEFORE="$val"
OPT_CONTEXT_AFTER="$val"
;;
-B*)
val="${arg:2}"
OPT_CONTEXT_BEFORE="$val"
;;
-A*)
val="${arg:2}"
OPT_CONTEXT_AFTER="$val"
;;
esac
done
fi
# Parse arguments.
while shiftopt; do
case "$OPT" in