Update batgrep to disabled highlights when -C=0

This commit is contained in:
Ethan P 2019-09-18 21:12:23 -07:00
parent daa54ba4cf
commit c8e22890fe
No known key found for this signature in database
GPG Key ID: 6963FD04F6CF35EA
2 changed files with 6 additions and 2 deletions

View File

@ -21,7 +21,8 @@ A script that combines [ripgrep](https://github.com/burntsushi/ripgrep) with bat
| `-B` | `--before-context=[LINES]` | Display the previous `n` lines before a matched line. | | `-B` | `--before-context=[LINES]` | Display the previous `n` lines before a matched line. |
| `-C` | `--context=[LINES]` | A combination of `--after-context` and `--before-context`. | | `-C` | `--context=[LINES]` | A combination of `--after-context` and `--before-context`. |
| | `--no-follow` | Do not follow symlinks. | | | `--no-follow` | Do not follow symlinks. |
| | `--no-snip` | Do not show the `snip` decoration.<br /><br />This is disabled when `--context=0` or when `bat --version` is less than `0.12.x`. | | | `--no-snip` | Do not show the `snip` decoration.<br /><br />This is automatically enabled when `--context=0` or when `bat --version` is less than `0.12.x`. |
| | `--no-highlight` | Do not highlight matching lines.<br /><br />This is automatically enabled when `--context=0`. |

View File

@ -20,6 +20,7 @@ OPT_CONTEXT_BEFORE=2
OPT_CONTEXT_AFTER=2 OPT_CONTEXT_AFTER=2
OPT_FOLLOW=true OPT_FOLLOW=true
OPT_SNIP="" OPT_SNIP=""
OPT_HIGHLIGHT=true
BAT_STYLE="header,numbers" BAT_STYLE="header,numbers"
# Set options based on the bat version. # Set options based on the bat version.
@ -63,6 +64,7 @@ while shiftopt; do
# Script Options # Script Options
--no-follow) OPT_FOLLOW=false;; --no-follow) OPT_FOLLOW=false;;
--no-snip) OPT_SNIP="";; --no-snip) OPT_SNIP="";;
--no-highlight) OPT_HIGHLIGHT=false;;
# ??? # ???
-*) { -*) {
@ -92,6 +94,7 @@ fi
if [[ "$OPT_CONTEXT_BEFORE" -eq 0 && "$OPT_CONTEXT_AFTER" -eq 0 ]]; then if [[ "$OPT_CONTEXT_BEFORE" -eq 0 && "$OPT_CONTEXT_AFTER" -eq 0 ]]; then
OPT_SNIP="" OPT_SNIP=""
OPT_HIGHLIGHT=false
fi fi
# Invoke ripgrep. # Invoke ripgrep.
@ -137,7 +140,7 @@ while IFS=':' read -r file line column; do
[[ "$line_start" -gt 0 ]] || line_start='' [[ "$line_start" -gt 0 ]] || line_start=''
LAST_LR+=("--line-range=${line_start}:${line_end}") LAST_LR+=("--line-range=${line_start}:${line_end}")
LAST_LH+=("--highlight-line=${line}") [[ "$OPT_HIGHLIGHT" = "true" ]] && LAST_LH+=("--highlight-line=${line}")
done < <(rg --with-filename --vimgrep "${RG_ARGS[@]}" --sort path "$PATTERN" "${FILES[@]}") done < <(rg --with-filename --vimgrep "${RG_ARGS[@]}" --sort path "$PATTERN" "${FILES[@]}")
do_print do_print