From 4d9b85356150f805b2a8119001b3094a5cc8c12f Mon Sep 17 00:00:00 2001 From: JacobTravers Date: Fri, 31 Mar 2023 13:53:39 -0700 Subject: [PATCH] Use grep -F when no argument is passed (literal string match) Why? Most users who pass the current selection to grep likely do not intend to pass the selection as a regex input string. This makes the grepcmd use an additional -F flag to perform literal-string matching for the current selection. The -F flag seems to be the standard flag for literal-string matching in every grep implementation I've found. --- rc/tools/grep.kak | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/rc/tools/grep.kak b/rc/tools/grep.kak index ec036385..6e6246e4 100644 --- a/rc/tools/grep.kak +++ b/rc/tools/grep.kak @@ -7,9 +7,10 @@ declare-option -hidden int grep_current_line 0 define-command -params .. -docstring %{ grep []: grep utility wrapper All optional arguments are forwarded to the grep utility + Passing no argument will perform a literal-string grep for the current selection } grep %{ evaluate-commands %sh{ if [ $# -eq 0 ]; then - set -- "${kak_selection}" + set -- -F "${kak_selection}" fi output=$(mktemp -d "${TMPDIR:-/tmp}"/kak-grep.XXXXXXXX)/fifo