dtach.kak (1185B)
1 provide-module dtach-repl %{ 2 3 # test if dtach is installed 4 evaluate-commands %sh{ 5 [ -n "$(command -v dtach)" ] || echo 'fail dtach not found' 6 } 7 8 declare-option -docstring "id of the REPL" str dtach_repl_id 9 10 define-command -docstring %{ 11 dtach-repl [<arguments>]: create a new terminal window for repl interaction 12 All optional parameters are forwarded to the new terminal window 13 } \ 14 -params .. \ 15 dtach-repl %{ terminal sh -c %{ 16 file="$(mktemp -u -t kak_dtach_repl.XXXXX)" 17 trap 'rm -f "${file}"' EXIT 18 printf "evaluate-commands -try-client $1 \ 19 'set-option current dtach_repl_id ${file}'" | kak -p "$2" 20 shift 2 21 dtach -c "${file}" -E sh -c "${@:-$SHELL}" || "${@:-$SHELL}" 22 } -- %val{client} %val{session} %arg{@} 23 } 24 complete-command dtach-repl shell 25 26 define-command dtach-send-text -params 0..1 -docstring %{ 27 dtach-send-text [text]: Send text to the REPL. 28 If no text is passed, then the selection is used 29 } %{ 30 nop %sh{ 31 printf "%s" "${@:-$kak_selection}" | dtach -p "$kak_opt_dtach_repl_id" 32 } 33 } 34 35 alias global repl-new dtach-repl 36 alias global repl-send-text dtach-send-text 37 38 }