kitty.kak (1403B)
1 hook global ModuleLoaded kitty %{ 2 require-module kitty-repl 3 } 4 5 provide-module kitty-repl %{ 6 7 define-command -params .. \ 8 -docstring %{ 9 kitty-repl [<arguments>]: Create a new window for repl interaction. 10 11 All optional parameters are forwarded to the new window. 12 } \ 13 kitty-repl %{ 14 nop %sh{ 15 if [ $# -eq 0 ]; then 16 cmd="${SHELL:-/bin/sh}" 17 else 18 cmd="$*" 19 fi 20 21 match="" 22 if [ -n "$kak_client_env_KITTY_WINDOW_ID" ]; then 23 match="--match=window_id:$kak_client_env_KITTY_WINDOW_ID" 24 fi 25 26 listen="" 27 if [ -n "$kak_client_env_KITTY_LISTEN_ON" ]; then 28 listen="--to=$kak_client_env_KITTY_LISTEN_ON" 29 fi 30 31 kitty @ $listen launch --no-response --keep-focus --type="$kak_opt_kitty_window_type" --title=kak_repl_window --cwd="$PWD" $match $cmd 32 } 33 } 34 complete-command kitty-repl shell 35 36 define-command -hidden -params 0..1 \ 37 -docstring %{ 38 kitty-send-text [text]: Send text to the REPL window. 39 40 If no text is passed, the selection is used. 41 } \ 42 kitty-send-text %{ 43 nop %sh{ 44 if [ $# -eq 0 ]; then 45 text="$kak_selection" 46 else 47 text="$1" 48 fi 49 kitty @ send-text --match=title:kak_repl_window "$text" 50 } 51 } 52 53 alias global repl-new kitty-repl 54 alias global repl-send-text kitty-send-text 55 56 }