From 7549ffd9862d418f94749613dd231da795a2763d Mon Sep 17 00:00:00 2001 From: Ethan P Date: Thu, 29 Oct 2020 01:28:26 -0700 Subject: [PATCH] batgrep: Clean up handling of RIPGREP_CONFIG_PATH --- src/batgrep.sh | 44 +++++++++++--------------------------------- 1 file changed, 11 insertions(+), 33 deletions(-) diff --git a/src/batgrep.sh b/src/batgrep.sh index 64bd703..eb6dd57 100755 --- a/src/batgrep.sh +++ b/src/batgrep.sh @@ -47,45 +47,23 @@ 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" + # shellcheck disable=SC2046 + setargs $(cat "$RIPGREP_CONFIG_PATH") + while shiftopt; do + case "$OPT" in + -A | --after-context) shiftval; OPT_CONTEXT_AFTER="$OPT_VAL" ;; + -B | --before-context) shiftval; OPT_CONTEXT_BEFORE="$OPT_VAL" ;; + -C | --context) + shiftval + OPT_CONTEXT_BEFORE="$OPT_VAL" + OPT_CONTEXT_AFTER="$OPT_VAL" ;; esac done fi # Parse arguments. +resetargs while shiftopt; do case "$OPT" in