mirror of
https://github.com/eth-p/bat-extras.git
synced 2025-06-20 11:47:43 +02:00
Add support for fixed strings and --less-search-pattern
Previously, if you tried to use the `-F`/`--fixed strings` option for ripgrep in combination with the `--less-search-pattern` option, `less` would either a) match a different pattern than intended, since it would be interpreted as a regular expression, or b) refuse to start if it detected an invalid pattern. This change keeps track of whether or not the `--fixed-strings` option was passed in. If both it and the `--less-search-pattern` was passed in, a `^R` (Control-R) control character is prepended to the search pattern. This instructs less to *not* treat the pattern as a regular expression.
This commit is contained in:
parent
cf7b33443a
commit
67f1ff9c0e
@ -31,6 +31,7 @@ OPT_FOLLOW=true
|
|||||||
OPT_SNIP=""
|
OPT_SNIP=""
|
||||||
OPT_HIGHLIGHT=true
|
OPT_HIGHLIGHT=true
|
||||||
OPT_SEARCH_PATTERN=false
|
OPT_SEARCH_PATTERN=false
|
||||||
|
OPT_FIXED_STRINGS=false
|
||||||
BAT_STYLE="header,numbers"
|
BAT_STYLE="header,numbers"
|
||||||
|
|
||||||
# Set options based on the bat version.
|
# Set options based on the bat version.
|
||||||
@ -51,7 +52,8 @@ while shiftopt; do
|
|||||||
-C|--context) shiftval; OPT_CONTEXT_BEFORE="$OPT_VAL";
|
-C|--context) shiftval; OPT_CONTEXT_BEFORE="$OPT_VAL";
|
||||||
OPT_CONTEXT_AFTER="$OPT_VAL";;
|
OPT_CONTEXT_AFTER="$OPT_VAL";;
|
||||||
|
|
||||||
-F|--fixed-strings|\
|
-F|--fixed-strings) OPT_FIXED_STRINGS=true; RG_ARGS+=("$OPT");;
|
||||||
|
|
||||||
-U|--multiline|\
|
-U|--multiline|\
|
||||||
-P|--pcre2|\
|
-P|--pcre2|\
|
||||||
-z|--search-zip|\
|
-z|--search-zip|\
|
||||||
@ -138,8 +140,18 @@ if [[ "$OPT_CONTEXT_BEFORE" -eq 0 && "$OPT_CONTEXT_AFTER" -eq 0 ]]; then
|
|||||||
fi
|
fi
|
||||||
|
|
||||||
if [[ "$OPT_LESS_SEARCH_PATTERN" = true ]]; then
|
if [[ "$OPT_LESS_SEARCH_PATTERN" = true ]]; then
|
||||||
|
if [[ "$OPT_FIXED_STRINGS" = true ]]; then
|
||||||
|
# Depending on your editor, this may look identical. However, there is a
|
||||||
|
# special control character at the beginning of the pattern string, right
|
||||||
|
# after the first double quote. It is a a ^R, or Control-R, character. This
|
||||||
|
# instructs less to NOT use regular expressions, which is what the -F flag
|
||||||
|
# does for ripgrep. If we did not use this, then less would match a
|
||||||
|
# different pattern than ripgrep searched for.
|
||||||
|
SCRIPT_PAGER_ARGS+=(-p "$PATTERN")
|
||||||
|
else
|
||||||
SCRIPT_PAGER_ARGS+=(-p "$PATTERN")
|
SCRIPT_PAGER_ARGS+=(-p "$PATTERN")
|
||||||
fi
|
fi
|
||||||
|
fi
|
||||||
|
|
||||||
# -----------------------------------------------------------------------------
|
# -----------------------------------------------------------------------------
|
||||||
# Main:
|
# Main:
|
||||||
|
Loading…
x
Reference in New Issue
Block a user