mirror of
https://github.com/mawww/kakoune.git
synced 2024-11-22 13:28:32 +03:00
Add a -script switch to the fifo to cater for grep/make use cases
Avoid the brittle `exit; %arg{@}` trick
This commit is contained in:
parent
ba504431dc
commit
880ad98a30
@ -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}
|
||||
|
@ -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
|
||||
}
|
||||
|
@ -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
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user