Merge remote-tracking branch 'listentolist/x11-repl' into master

This commit is contained in:
Maxime Coste 2020-11-01 10:10:39 +11:00
commit 5d6136483c

View File

@ -4,29 +4,28 @@ hook global ModuleLoaded x11 %{
provide-module x11-repl %{ provide-module x11-repl %{
# termcmd should already be set in x11.kak declare-option -docstring "window id of the REPL window" str x11_repl_id
define-command -docstring %{ define-command -docstring %{
x11-repl [<arguments>]: create a new window for repl interaction x11-repl [<arguments>]: create a new window for repl interaction
All optional parameters are forwarded to the new window All optional parameters are forwarded to the new window
} \ } \
-params .. \ -params .. \
-shell-completion \ -shell-completion \
x11-repl %{ evaluate-commands %sh{ x11-repl %{ x11-terminal sh -c %{
if [ -z "${kak_opt_termcmd}" ]; then winid="${WINDOWID:-$(xdotool search --pid ${PPID} | tail -1)}"
echo 'fail termcmd option is not set' printf "evaluate-commands -try-client $1 \
exit 'set-option current x11_repl_id ${winid}'" | kak -p "$2"
fi shift 2;
if [ $# -eq 0 ]; then cmd="${SHELL:-sh}"; else cmd="$@"; fi [ "$1" ] && "$@" || "$SHELL"
# The escape sequence in the printf command sets the terminal's title: } -- %val{client} %val{session} %arg{@}
setsid ${kak_opt_termcmd} "printf '\e]2;kak_repl_window\a' \ }
&& ${cmd}" < /dev/null > /dev/null 2>&1 &
}}
define-command x11-send-text -docstring "send the selected text to the repl window" %{ define-command x11-send-text -docstring "send the selected text to the repl window" %{
evaluate-commands %sh{ evaluate-commands %sh{
printf %s\\n "${kak_selection}" | xsel -i || printf %s\\n "${kak_selection}" | xsel -i ||
echo 'fail x11-send-text: failed to run xsel, see *debug* buffer for details' && echo 'fail x11-send-text: failed to run xsel, see *debug* buffer for details' &&
xdotool search --name kak_repl_window key --clearmodifiers Shift+Insert || xdotool windowactivate "${kak_opt_x11_repl_id}" key --clearmodifiers Shift+Insert ||
echo 'fail x11-send-text: failed to run xdotool, see *debug* buffer for details' echo 'fail x11-send-text: failed to run xdotool, see *debug* buffer for details'
} }
} }