From 4d9b85356150f805b2a8119001b3094a5cc8c12f Mon Sep 17 00:00:00 2001 From: JacobTravers Date: Fri, 31 Mar 2023 13:53:39 -0700 Subject: [PATCH 1/4] 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 From d8b9b13d079b5282e82d83be04b43f57b12ee0d3 Mon Sep 17 00:00:00 2001 From: JacobTravers Date: Wed, 5 Apr 2023 15:34:37 -0700 Subject: [PATCH 2/4] apply literal flag according to grep tool --- rc/tools/grep.kak | 20 +++++++++++++++++--- 1 file changed, 17 insertions(+), 3 deletions(-) diff --git a/rc/tools/grep.kak b/rc/tools/grep.kak index 6e6246e4..292f2570 100644 --- a/rc/tools/grep.kak +++ b/rc/tools/grep.kak @@ -9,9 +9,23 @@ define-command -params .. -docstring %{ 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 -- -F "${kak_selection}" - fi + if [ $# -eq 0 ]; then + IFS=" " greptool=$( + set -- $kak_opt_grepcmd + echo "$1" + ) + case "$greptool" in + ag | grep | rg | ripgrep | ugrep | ug) + set -- -F "${kak_selection}" + ;; + ack ) + set -- -Q "${kak_selection}" + ;; + *) + set -- "${kak_selection}" + ;; + esac + fi output=$(mktemp -d "${TMPDIR:-/tmp}"/kak-grep.XXXXXXXX)/fifo mkfifo ${output} From cac21675409a4b5755fab2f00bdf5ce6451b42aa Mon Sep 17 00:00:00 2001 From: JacobTravers Date: Thu, 6 Apr 2023 10:20:52 -0700 Subject: [PATCH 3/4] case directly to $kak_opt_grepcmd --- rc/tools/grep.kak | 10 +++------- 1 file changed, 3 insertions(+), 7 deletions(-) diff --git a/rc/tools/grep.kak b/rc/tools/grep.kak index 292f2570..2ce23e72 100644 --- a/rc/tools/grep.kak +++ b/rc/tools/grep.kak @@ -10,15 +10,11 @@ define-command -params .. -docstring %{ Passing no argument will perform a literal-string grep for the current selection } grep %{ evaluate-commands %sh{ if [ $# -eq 0 ]; then - IFS=" " greptool=$( - set -- $kak_opt_grepcmd - echo "$1" - ) - case "$greptool" in - ag | grep | rg | ripgrep | ugrep | ug) + case "$kak_opt_grepcmd" in + ag\ * | git\ grep\ * | grep\ * | rg\ * | ripgrep\ * | ugrep\ * | ug\ *) set -- -F "${kak_selection}" ;; - ack ) + ack\ *) set -- -Q "${kak_selection}" ;; *)