aboutsummaryrefslogtreecommitdiff
path: root/dot_config/kak/autoload/rc/windowing/repl/dtach.kak
diff options
context:
space:
mode:
authortwells46 <173561638+twells46@users.noreply.github.com>2025-12-31 13:28:05 -0600
committertwells46 <173561638+twells46@users.noreply.github.com>2025-12-31 13:28:05 -0600
commit2140ab51deed88e90eafebf9520fa5f9995dc7c9 (patch)
tree03cf1dcd2900495c1efb79aaa85f3254ecd5fb87 /dot_config/kak/autoload/rc/windowing/repl/dtach.kak
parentff8f50638e4b17a9d7cc88d2f0d9560b7effce39 (diff)
Migrate from stow
Diffstat (limited to 'dot_config/kak/autoload/rc/windowing/repl/dtach.kak')
-rw-r--r--dot_config/kak/autoload/rc/windowing/repl/dtach.kak38
1 files changed, 38 insertions, 0 deletions
diff --git a/dot_config/kak/autoload/rc/windowing/repl/dtach.kak b/dot_config/kak/autoload/rc/windowing/repl/dtach.kak
new file mode 100644
index 0000000..02d11ec
--- /dev/null
+++ b/dot_config/kak/autoload/rc/windowing/repl/dtach.kak
@@ -0,0 +1,38 @@
+provide-module dtach-repl %{
+
+# test if dtach is installed
+evaluate-commands %sh{
+ [ -n "$(command -v dtach)" ] || echo 'fail dtach not found'
+}
+
+declare-option -docstring "id of the REPL" str dtach_repl_id
+
+define-command -docstring %{
+ dtach-repl [<arguments>]: create a new terminal window for repl interaction
+ All optional parameters are forwarded to the new terminal window
+} \
+ -params .. \
+ dtach-repl %{ terminal sh -c %{
+ file="$(mktemp -u -t kak_dtach_repl.XXXXX)"
+ trap 'rm -f "${file}"' EXIT
+ printf "evaluate-commands -try-client $1 \
+ 'set-option current dtach_repl_id ${file}'" | kak -p "$2"
+ shift 2
+ dtach -c "${file}" -E sh -c "${@:-$SHELL}" || "${@:-$SHELL}"
+ } -- %val{client} %val{session} %arg{@}
+}
+complete-command dtach-repl shell
+
+define-command dtach-send-text -params 0..1 -docstring %{
+ dtach-send-text [text]: Send text to the REPL.
+ If no text is passed, then the selection is used
+ } %{
+ nop %sh{
+ printf "%s" "${@:-$kak_selection}" | dtach -p "$kak_opt_dtach_repl_id"
+ }
+}
+
+alias global repl-new dtach-repl
+alias global repl-send-text dtach-send-text
+
+}