2019-06-25 17:48:24 +02:00
|
|
|
hook global ModuleLoaded x11 %{
|
2019-03-13 22:00:59 +01:00
|
|
|
require-module x11-repl
|
|
|
|
}
|
|
|
|
|
|
|
|
provide-module x11-repl %{
|
|
|
|
|
2020-10-27 11:12:09 +01:00
|
|
|
declare-option -docstring "window id of the REPL window" str x11_repl_id
|
|
|
|
|
2020-02-03 20:53:28 +01:00
|
|
|
define-command -docstring %{
|
|
|
|
x11-repl [<arguments>]: create a new window for repl interaction
|
|
|
|
All optional parameters are forwarded to the new window
|
|
|
|
} \
|
2016-10-11 09:03:41 +02:00
|
|
|
-params .. \
|
2023-11-01 11:21:19 +01:00
|
|
|
x11-repl %{ x11-terminal-window sh -c %{
|
2020-10-30 14:35:20 +01:00
|
|
|
winid="${WINDOWID:-$(xdotool search --pid ${PPID} | tail -1)}"
|
2020-10-27 22:57:04 +01:00
|
|
|
printf "evaluate-commands -try-client $1 \
|
2020-10-30 14:35:20 +01:00
|
|
|
'set-option current x11_repl_id ${winid}'" | kak -p "$2"
|
2020-10-27 22:57:04 +01:00
|
|
|
shift 2;
|
|
|
|
[ "$1" ] && "$@" || "$SHELL"
|
|
|
|
} -- %val{client} %val{session} %arg{@}
|
|
|
|
}
|
2022-02-22 10:14:47 +01:00
|
|
|
complete-command x11-repl shell
|
2016-01-26 14:05:35 +01:00
|
|
|
|
2021-01-16 16:51:41 +01:00
|
|
|
define-command x11-send-text -params 0..1 -docstring %{
|
|
|
|
x11-send-text [text]: Send text to the REPL window.
|
|
|
|
If no text is passed, then the selection is used
|
|
|
|
} %{
|
2020-07-11 18:23:27 +02:00
|
|
|
evaluate-commands %sh{
|
2021-02-02 07:53:29 +01:00
|
|
|
([ "$#" -gt 0 ] && printf "%s" "$1" || printf "%s" "${kak_selection}" ) | xsel -i ||
|
2020-07-11 18:23:27 +02:00
|
|
|
echo 'fail x11-send-text: failed to run xsel, see *debug* buffer for details' &&
|
2021-01-16 16:51:41 +01:00
|
|
|
kak_winid=$(xdotool getactivewindow) &&
|
|
|
|
xdotool windowactivate "${kak_opt_x11_repl_id}" key --clearmodifiers Shift+Insert &&
|
|
|
|
xdotool windowactivate "${kak_winid}" ||
|
2020-07-11 18:23:27 +02:00
|
|
|
echo 'fail x11-send-text: failed to run xdotool, see *debug* buffer for details'
|
2016-01-26 14:05:35 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-09-01 12:30:34 +02:00
|
|
|
alias global repl-new x11-repl
|
|
|
|
alias global repl-send-text x11-send-text
|
2019-03-13 22:00:59 +01:00
|
|
|
|
|
|
|
}
|