summaryrefslogtreecommitdiff
path: root/rc
diff options
context:
space:
mode:
authorMaxime Coste <mawww@kakoune.org>2024-06-22 17:02:54 +1000
committerMaxime Coste <mawww@kakoune.org>2024-06-22 17:02:54 +1000
commit880ad98a30e7373909284100c45e065a573fd5c8 (patch)
treecbf70410fbac387d6cbfbdb38c7122f38c35874c /rc
parentba504431dcfae4d68c905c4a0b63ea96a68fc5ac (diff)
Add a -script switch to the fifo to cater for grep/make use cases
Avoid the brittle `exit; %arg{@}` trick
Diffstat (limited to 'rc')
-rw-r--r--rc/tools/fifo.kak10
-rw-r--r--rc/tools/grep.kak5
-rw-r--r--rc/tools/make.kak5
3 files changed, 12 insertions, 8 deletions
diff --git a/rc/tools/fifo.kak b/rc/tools/fifo.kak
index f1f78d23..ea98c0e2 100644
--- a/rc/tools/fifo.kak
+++ b/rc/tools/fifo.kak
@@ -1,12 +1,14 @@
provide-module fifo %{
define-command -params .. -docstring %{
- fifo [-name <buffer-name>] [-scroll] [--] <command>...: run command in a fifo buffer
+ fifo [-name <name>] [-scroll] [-script <script>] [--] <args>...: run command in a fifo buffer
+ if <script> is used, eval it with <args> as '$@', else pass arguments directly to the shell
} fifo %{ evaluate-commands %sh{
name='*fifo*'
while true; do
case "$1" in
"-scroll") scroll="-scroll"; shift ;;
+ "-script") script="$2"; shift 2 ;;
"-name") name="$2"; shift 2 ;;
"--") shift; break ;;
*) break ;;
@@ -14,7 +16,11 @@ define-command -params .. -docstring %{
done
output=$(mktemp -d "${TMPDIR:-/tmp}"/kak-fifo.XXXXXXXX)/fifo
mkfifo ${output}
- ( eval "$@" > ${output} 2>&1 & ) > /dev/null 2>&1 < /dev/null
+ if [ -n "$script" ]; then
+ ( eval "$script" > ${output} 2>&1 & ) > /dev/null 2>&1 < /dev/null
+ else
+ ( "$@" > ${output} 2>&1 & ) > /dev/null 2>&1 < /dev/null
+ fi
printf %s\\n "
edit! -fifo ${output} ${scroll} ${name}
diff --git a/rc/tools/grep.kak b/rc/tools/grep.kak
index 08c5ae75..e962815f 100644
--- a/rc/tools/grep.kak
+++ b/rc/tools/grep.kak
@@ -12,8 +12,7 @@ define-command -params .. -docstring %{
Passing no argument will perform a literal-string grep for the current selection
} grep %{
evaluate-commands -try-client %opt{toolsclient} %{
- fifo -name *grep* %{
- shift 2
+ fifo -name *grep* -script %{
trap - INT QUIT
if [ $# -eq 0 ]; then
case "$kak_opt_grepcmd" in
@@ -29,7 +28,7 @@ define-command -params .. -docstring %{
esac
fi
$kak_opt_grepcmd "$@" 2>&1 | tr -d '\r'
- } 'exit;' %arg{@} # pass arguments for "$@" above, exit to avoid evaluating them
+ } %arg{@}
set-option buffer filetype grep
set-option buffer jump_current_line 0
}
diff --git a/rc/tools/make.kak b/rc/tools/make.kak
index f1b277ce..5a0896b2 100644
--- a/rc/tools/make.kak
+++ b/rc/tools/make.kak
@@ -13,11 +13,10 @@ define-command -params .. -docstring %{
All the optional arguments are forwarded to the make utility
} make %{
evaluate-commands -try-client %opt{toolsclient} %{
- fifo -scroll -name *make* %{
- shift 2
+ fifo -scroll -name *make* -script %{
trap - INT QUIT
$kak_opt_makecmd "$@"
- } 'exit;' %arg{@} # pass arguments for "$@" above, exit to avoid evaluating them
+ } %arg{@} # pass arguments for "$@" above, exit to avoid evaluating them
set-option buffer filetype make
set-option buffer jump_current_line 0
}