Reset SIGINT handler in background processes

In a noninteractive shell, asynchronous commands ignore SIGINT and
SIGQUIT. We typically use such shells to feed fifo buffers which we
do want to cancel them on Control-C.  Make it so.

Same for SIGQUIT; that one is not typically used but I expect that
along the Kakoune server it kills any child processes that (haven't
been daemonized).

Note that for unknown reasons, Bash already doesn't ignore SIGINT in
async processes that use "eval".

Note that Dash has a bug that prevents this from working;
proposed fix is at
https://lore.kernel.org/dash/20240329153905.154792-2-aclopte@gmail.com/

(While at it balance out some parens, to help the m command)
This commit is contained in:
Johannes Altmanninger 2024-03-29 17:27:27 +01:00 committed by Maxime Coste
parent 5d00b80d1a
commit 7b93567bb1
10 changed files with 17 additions and 9 deletions

View File

@ -36,16 +36,17 @@ define-command -params ..1 \
# position and a buffer timestamp, only valid completions should be
# displayed.
((
trap - INT QUIT
until [ -f ${dir}/buf ]; do :; done # wait for the buffer to be written
if [ -n "$kak_opt_clang_directory" ]; then
cd "$kak_opt_clang_directory"
fi
case ${kak_opt_filetype} in
c) ft=c ;;
cpp) ft=c++ ;;
obj-c) ft=objective-c ;;
*) ft=c++ ;;
(c) ft=c ;;
(cpp) ft=c++ ;;
(obj-c) ft=objective-c ;;
(*) ft=c++ ;;
esac
if [ "$1" = "-complete" ]; then

View File

@ -112,6 +112,7 @@ declare-option -docstring "path to the directory in which the tags file will be
define-command ctags-generate -docstring 'Generate tag file asynchronously' %{
echo -markup "{Information}launching tag generation in the background"
nop %sh{ (
trap - INT QUIT
while ! mkdir .tags.kaklock 2>/dev/null; do sleep 1; done
trap 'rmdir .tags.kaklock' EXIT
@ -128,6 +129,7 @@ define-command ctags-generate -docstring 'Generate tag file asynchronously' %{
define-command ctags-update-tags -docstring 'Update tags for the given file' %{
nop %sh{ (
trap - INT QUIT
while ! mkdir .tags.kaklock 2>/dev/null; do sleep 1; done
trap 'rmdir .tags.kaklock' EXIT

View File

@ -164,7 +164,7 @@ define-command -params 1.. \
esac
output=$(mktemp -d "${TMPDIR:-/tmp}"/kak-git.XXXXXXXX)/fifo
mkfifo ${output}
( git "$@" > ${output} 2>&1 & ) > /dev/null 2>&1 < /dev/null
( trap - INT QUIT; git "$@" > ${output} 2>&1 & ) > /dev/null 2>&1 < /dev/null
printf %s "evaluate-commands -try-client '$kak_opt_docsclient' '
edit! -fifo ${output} *git*
@ -283,6 +283,7 @@ define-command -params 1.. \
echo 'map window normal <ret> %{:git blame-jump<ret>}'
echo 'echo -markup {Information}Press <ret> to jump to blamed commit'
(
trap - INT QUIT
cd_bufdir
printf %s "evaluate-commands -client '$kak_client' %{
set-option buffer=$kak_bufname git_blame_flags '$kak_timestamp'

View File

@ -84,8 +84,8 @@ define-command -hidden -params 0 gopls-ref %{
evaluate-commands %sh{
dir=${kak_opt_gopls_tmp_dir}
mkfifo "${dir}/fifo"
( gopls references "${kak_buffile}:${kak_cursor_line}:${kak_cursor_column}" \
> "${dir}/fifo" 2> /dev/null & ) > /dev/null 2>&1 < /dev/null
( { trap - INT QUIT; gopls references "${kak_buffile}:${kak_cursor_line}:${kak_cursor_column}"
} > "${dir}/fifo" 2> /dev/null & ) > /dev/null 2>&1 < /dev/null
# using filetype=grep for nice hilight and <ret> mapping
printf %s\\n "evaluate-commands -try-client '${kak_opt_toolsclient}' %{
edit! -fifo '${dir}/fifo' *gopls-refs*

View File

@ -26,7 +26,7 @@ define-command -params .. -docstring %{
output=$(mktemp -d "${TMPDIR:-/tmp}"/kak-grep.XXXXXXXX)/fifo
mkfifo ${output}
( ${kak_opt_grepcmd} "$@" 2>&1 | tr -d '\r' > ${output} 2>&1 & ) > /dev/null 2>&1 < /dev/null
( { 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*

View File

@ -74,6 +74,7 @@ define-command \
# but shellcheck isn't a fan.
# shellcheck disable=SC2094
({ # do the parsing in the background and when ready send to the session
trap - INT QUIT
for selpath in "$dir"/sel-*; do
# Read in the line and column offset of this selection.

View File

@ -14,7 +14,7 @@ define-command -params .. \
} make %{ evaluate-commands %sh{
output=$(mktemp -d "${TMPDIR:-/tmp}"/kak-make.XXXXXXXX)/fifo
mkfifo ${output}
( eval "${kak_opt_makecmd}" "$@" > ${output} 2>&1 & ) > /dev/null 2>&1 < /dev/null
( { 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*

View File

@ -20,6 +20,7 @@ define-command jedi-complete -docstring "Complete the current selection" %{
dir=${kak_opt_jedi_tmp_dir}
printf %s\\n "evaluate-commands -draft %{ edit! -fifo ${dir}/fifo *jedi-output* }"
((
trap - INT QUIT
cd $(dirname ${kak_buffile})
export PYTHONPATH="$kak_opt_jedi_python_path:$PYTHONPATH"

View File

@ -16,6 +16,7 @@ define-command racer-complete -docstring "Complete the current selection with ra
evaluate-commands %sh{
dir=${kak_opt_racer_tmp_dir}
(
trap - INT QUIT
cursor="${kak_cursor_line} $((${kak_cursor_column} - 1))"
racer_data=$(racer --interface tab-text complete-with-snippet ${cursor} ${kak_buffile} ${dir}/buf)
compl=$(printf %s\\n "${racer_data}" | awk '

View File

@ -32,6 +32,7 @@ define-command -params ..1 -docstring %{
printf 'eval -no-hooks write %s\n' "${kak_response_fifo}" > $kak_command_fifo
{
trap - INT QUIT
sed 's/^/^/' | eval "aspell --byte-offsets -a $options" 2>&1 | awk '
BEGIN {
line_num = 1