summaryrefslogtreecommitdiff
path: root/rc
diff options
context:
space:
mode:
authorMaxime Coste <mawww@kakoune.org>2024-06-07 19:03:50 +1000
committerMaxime Coste <mawww@kakoune.org>2024-06-07 19:03:50 +1000
commitc93cb5c4d8f1c2aec21f8bdeba59dfb8f153499c (patch)
tree4b17990a35a42257f77c9631820b9c8a0e4e4fc8 /rc
parent1bdae3f9c4e554c62100560d48957d42f5ae17e0 (diff)
Add a `fifo` helper command and refactor `make` and `grep` to use it
Running arbitrary commands in a fifo is very useful in its own right and factoring out the common pattern is a nice added cleanup.
Diffstat (limited to 'rc')
-rw-r--r--rc/tools/fifo.kak29
-rw-r--r--rc/tools/grep.kak51
-rw-r--r--rc/tools/make.kak31
3 files changed, 69 insertions, 42 deletions
diff --git a/rc/tools/fifo.kak b/rc/tools/fifo.kak
new file mode 100644
index 00000000..f1f78d23
--- /dev/null
+++ b/rc/tools/fifo.kak
@@ -0,0 +1,29 @@
+provide-module fifo %{
+
+define-command -params .. -docstring %{
+ fifo [-name <buffer-name>] [-scroll] [--] <command>...: run command in a fifo buffer
+} fifo %{ evaluate-commands %sh{
+ name='*fifo*'
+ while true; do
+ case "$1" in
+ "-scroll") scroll="-scroll"; shift ;;
+ "-name") name="$2"; shift 2 ;;
+ "--") shift; break ;;
+ *) break ;;
+ esac
+ done
+ output=$(mktemp -d "${TMPDIR:-/tmp}"/kak-fifo.XXXXXXXX)/fifo
+ mkfifo ${output}
+ ( eval "$@" > ${output} 2>&1 & ) > /dev/null 2>&1 < /dev/null
+
+ printf %s\\n "
+ edit! -fifo ${output} ${scroll} ${name}
+ hook -always -once buffer BufCloseFifo .* %{ nop %sh{ rm -r $(dirname ${output}) } }
+ "
+ }}
+
+complete-command fifo shell
+
+}
+
+hook -once global KakBegin .* %{ require-module fifo }
diff --git a/rc/tools/grep.kak b/rc/tools/grep.kak
index 13b5b9c3..08c5ae75 100644
--- a/rc/tools/grep.kak
+++ b/rc/tools/grep.kak
@@ -3,38 +3,37 @@ declare-option -docstring "shell command run to search for subtext in a file/dir
provide-module grep %{
+require-module fifo
require-module jump
define-command -params .. -docstring %{
grep [<arguments>]: 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
- case "$kak_opt_grepcmd" in
- ag\ * | git\ grep\ * | 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}
- ( { trap - INT QUIT; ${kak_opt_grepcmd} "$@" 2>&1 | tr -d '\r'; } > ${output} 2>&1 & ) > /dev/null 2>&1 < /dev/null
-
- printf %s\\n "evaluate-commands -try-client '$kak_opt_toolsclient' %{
- edit! -fifo ${output} *grep*
- set-option buffer filetype grep
- set-option buffer jump_current_line 0
- hook -always -once buffer BufCloseFifo .* %{ nop %sh{ rm -r $(dirname ${output}) } }
- }"
-}}
+} grep %{
+ evaluate-commands -try-client %opt{toolsclient} %{
+ fifo -name *grep* %{
+ shift 2
+ trap - INT QUIT
+ if [ $# -eq 0 ]; then
+ case "$kak_opt_grepcmd" in
+ ag\ * | git\ grep\ * | grep\ * | rg\ * | ripgrep\ * | ugrep\ * | ug\ *)
+ set -- -F "$kak_selection"
+ ;;
+ ack\ *)
+ set -- -Q "$kak_selection"
+ ;;
+ *)
+ set -- "$kak_selection"
+ ;;
+ esac
+ fi
+ $kak_opt_grepcmd "$@" 2>&1 | tr -d '\r'
+ } 'exit;' %arg{@} # pass arguments for "$@" above, exit to avoid evaluating them
+ set-option buffer filetype grep
+ set-option buffer jump_current_line 0
+ }
+}
complete-command grep file
hook -group grep-highlight global WinSetOption filetype=grep %{
diff --git a/rc/tools/make.kak b/rc/tools/make.kak
index 61d9b6ce..f1b277ce 100644
--- a/rc/tools/make.kak
+++ b/rc/tools/make.kak
@@ -5,24 +5,23 @@ declare-option -docstring "pattern that describes lines containing information a
provide-module make %{
+require-module fifo
require-module jump
-define-command -params .. \
- -docstring %{
- make [<arguments>]: make utility wrapper
- All the optional arguments are forwarded to the make utility
- } make %{ evaluate-commands %sh{
- output=$(mktemp -d "${TMPDIR:-/tmp}"/kak-make.XXXXXXXX)/fifo
- mkfifo ${output}
- ( { trap - INT QUIT; eval "${kak_opt_makecmd}" "$@"; } > ${output} 2>&1 & ) > /dev/null 2>&1 < /dev/null
-
- printf %s\\n "evaluate-commands -try-client '$kak_opt_toolsclient' %{
- edit! -fifo ${output} -scroll *make*
- set-option buffer filetype make
- set-option buffer jump_current_line 0
- hook -always -once buffer BufCloseFifo .* %{ nop %sh{ rm -r $(dirname ${output}) } }
- }"
-}}
+define-command -params .. -docstring %{
+ make [<arguments>]: make utility wrapper
+ All the optional arguments are forwarded to the make utility
+} make %{
+ evaluate-commands -try-client %opt{toolsclient} %{
+ fifo -scroll -name *make* %{
+ shift 2
+ trap - INT QUIT
+ $kak_opt_makecmd "$@"
+ } 'exit;' %arg{@} # pass arguments for "$@" above, exit to avoid evaluating them
+ set-option buffer filetype make
+ set-option buffer jump_current_line 0
+ }
+}
add-highlighter shared/make group
add-highlighter shared/make/ regex "^([^:\n]+):(\d+):(?:(\d+):)?\h+(?:((?:fatal )?error)|(warning)|(note)|(required from(?: here)?))?.*?$" 1:cyan 2:green 3:green 4:red 5:yellow 6:blue 7:yellow