x11.kak (1472B)
1 hook global ModuleLoaded x11 %{ 2 require-module x11-repl 3 } 4 5 provide-module x11-repl %{ 6 7 declare-option -docstring "window id of the REPL window" str x11_repl_id 8 9 define-command -docstring %{ 10 x11-repl [<arguments>]: create a new window for repl interaction 11 All optional parameters are forwarded to the new window 12 } \ 13 -params .. \ 14 x11-repl %{ x11-terminal-window sh -c %{ 15 winid="${WINDOWID:-$(xdotool search --pid ${PPID} | tail -1)}" 16 printf "evaluate-commands -try-client $1 \ 17 'set-option current x11_repl_id ${winid}'" | kak -p "$2" 18 shift 2; 19 [ "$1" ] && "$@" || "$SHELL" 20 } -- %val{client} %val{session} %arg{@} 21 } 22 complete-command x11-repl shell 23 24 define-command x11-send-text -params 0..1 -docstring %{ 25 x11-send-text [text]: Send text to the REPL window. 26 If no text is passed, then the selection is used 27 } %{ 28 evaluate-commands %sh{ 29 ([ "$#" -gt 0 ] && printf "%s" "$1" || printf "%s" "${kak_selection}" ) | xsel -i || 30 echo 'fail x11-send-text: failed to run xsel, see *debug* buffer for details' && 31 kak_winid=$(xdotool getactivewindow) && 32 xdotool windowactivate "${kak_opt_x11_repl_id}" key --clearmodifiers Shift+Insert && 33 xdotool windowactivate "${kak_winid}" || 34 echo 'fail x11-send-text: failed to run xdotool, see *debug* buffer for details' 35 } 36 } 37 38 alias global repl-new x11-repl 39 alias global repl-send-text x11-send-text 40 41 }