zellij.kak (2553B)
1 # https://zellij.dev/ 2 # ‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾ 3 4 provide-module zellij %{ 5 6 # ensure we're running under zellij 7 evaluate-commands %sh{ 8 [ -z "${kak_opt_windowing_modules}" ] || [ -n "$ZELLIJ" -a -n "$ZELLIJ_SESSION_NAME" ] || echo 'fail zellij not detected' 9 } 10 11 define-command -params 1.. zellij-action %{ nop %sh{ 12 zellij --session "$kak_client_env_ZELLIJ_SESSION_NAME" action "$@" 13 }} 14 define-command -hidden -params 2.. zellij-run %{ nop %sh{ 15 zellij_run_options=$1 16 shift 17 zellij --session "$kak_client_env_ZELLIJ_SESSION_NAME" run $zellij_run_options -- "$@" 18 }} 19 20 define-command -hidden -params 1.. zellij-terminal-window %{ 21 zellij-run "--close-on-exit" %arg{@} 22 } 23 complete-command zellij-terminal-window shell 24 25 define-command zellij-terminal-vertical -params 1.. -docstring ' 26 zellij-terminal-vertical <program> [<arguments>]: create a new terminal as a zellij pane 27 The current pane is split into two, top and bottom 28 The program passed as argument will be executed in the new terminal' \ 29 %{ 30 zellij-run "--direction down" %arg{@} 31 } 32 complete-command zellij-terminal-vertical shell 33 34 define-command zellij-terminal-horizontal -params 1.. -docstring ' 35 zellij-terminal-horizontal <program> [<arguments>]: create a new terminal as a zellij pane 36 The current pane is split into two, left and right 37 The program passed as argument will be executed in the new terminal' \ 38 %{ 39 zellij-run "--direction right" %arg{@} 40 } 41 complete-command zellij-terminal-horizontal shell 42 43 define-command zellij-focus -params ..1 -docstring ' 44 zellij-focus [<client>]: focus the given client 45 If no client is passed then the current one is used' \ 46 %{ evaluate-commands %sh{ 47 if [ $# -eq 1 ]; then 48 printf "evaluate-commands -client '%s' focus" "$1" 49 elif [ -n "${kak_client_env_ZELLIJ_PANE_ID}" ]; then 50 zellij action focus-pane-id "${kak_client_env_ZELLIJ_PANE_ID}" 51 elif [ -n "${kak_client_env_ZELLIJ}" ]; then 52 output=$(mktemp -d "${TMPDIR:-/tmp}"/kak-zellij.XXXXXXXX)/dump-screen 53 pane_count=0 54 while [ $((pane_count+=1)) -lt 10 ]; do 55 if zellij action dump-screen "$output" && grep "${kak_client}@\[$kak_session\]" "$output" > /dev/null ; then 56 break; 57 fi 58 zellij action focus-next-pane 59 done 60 rm -r $(dirname $output) 61 fi 62 }} 63 complete-command -menu zellij-focus client 64 65 ## The default behaviour for the `new` command is to open an horizontal pane in a zellij session 66 alias global focus zellij-focus 67 68 } 69