From 5f5023d056eff6027da04ce55ab7f93985b30c01 Mon Sep 17 00:00:00 2001 From: Ethan P Date: Fri, 2 Oct 2020 20:09:00 -0700 Subject: [PATCH] batgrep: Add simple parsing of RIPGREP_CONFIG_PATH. --- src/batgrep.sh | 40 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 40 insertions(+) diff --git a/src/batgrep.sh b/src/batgrep.sh index 52c3c32..3f9cbd1 100755 --- a/src/batgrep.sh +++ b/src/batgrep.sh @@ -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