From 4ff5de6273118877c0120f0ee115c1bbbb42532f Mon Sep 17 00:00:00 2001 From: Bob Date: Fri, 17 Feb 2023 12:08:38 +0800 Subject: [PATCH 1/5] Create zellij.kak --- rc/windowing/detection.kak | 2 +- rc/windowing/zellij.kak | 74 ++++++++++++++++++++++++++++++++++++++ 2 files changed, 75 insertions(+), 1 deletion(-) create mode 100644 rc/windowing/zellij.kak diff --git a/rc/windowing/detection.kak b/rc/windowing/detection.kak index c47ca0a3..6e4b71e0 100644 --- a/rc/windowing/detection.kak +++ b/rc/windowing/detection.kak @@ -23,7 +23,7 @@ declare-option -docstring \ "Ordered list of windowing modules to try and load. An empty list disables both automatic module loading and environment detection, enabling complete manual control of the module loading." \ -str-list windowing_modules 'tmux' 'screen' 'kitty' 'iterm' 'sway' 'wayland' 'x11' +str-list windowing_modules 'tmux' 'screen' 'zellij' 'kitty' 'iterm' 'sway' 'wayland' 'x11' hook -group windowing global KakBegin .* %{ diff --git a/rc/windowing/zellij.kak b/rc/windowing/zellij.kak new file mode 100644 index 00000000..f4ef85d0 --- /dev/null +++ b/rc/windowing/zellij.kak @@ -0,0 +1,74 @@ +# https://zellij.dev/ +# ‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾ + +provide-module zellij %{ + +# ensure we're running under zellij +evaluate-commands %sh{ + [ -z "${kak_opt_windowing_modules}" ] || [ -n "$ZELLIJ" ] || echo 'fail zellij not detected' +} + +declare-option -hidden -docstring %{zellij run options (please check out "zellij run --help" for detail)}\ + str zellij_run_options "" + +define-command -hidden -params .. zellij-run %{ + nop %sh{ + zellij run ${kak_opt_zellij_run_options} -- $SHELL -i -c "$*" < /dev/null > /dev/null 2>&1 & + } + set global zellij_run_options "" + unset buffer zellij_run_options + unset window zellij_run_options +} + +define-command -hidden -params 1.. zellij-terminal-impl %{ + set global zellij_run_options "--close-on-exit" + zellij-run %arg{@} +} +complete-command zellij-terminal-impl shell + +define-command zellij-terminal-vertical -params 1.. -docstring ' +zellij-terminal-vertical []: create a new terminal as a zellij pane +The current pane is split into two, top and bottom +The program passed as argument will be executed in the new terminal' \ +%{ + set global zellij_run_options "--direction down" + zellij-run %arg{@} +} +complete-command zellij-terminal-vertical shell + +define-command zellij-terminal-horizontal -params 1.. -docstring ' +zellij-terminal-horizontal []: create a new terminal as a zellij pane +The current pane is split into two, left and right +The program passed as argument will be executed in the new terminal' \ +%{ + set global zellij_run_options "--direction right" + zellij-run %arg{@} +} +complete-command zellij-terminal-horizontal shell + +define-command zellij-focus -params ..1 -docstring ' +zellij-focus []: focus the given client +If no client is passed then the current one is used' \ +%{ evaluate-commands %sh{ + if [ $# -eq 1 ]; then + printf "evaluate-commands -client '%s' focus" "$1" + elif [ -n "${kak_client_env_ZELLIJ}" ]; then + output=$(mktemp -d "${TMPDIR:-/tmp}"/kak-zellij.XXXXXXXX)/dump-screen + pane_count=0 + while [ $((pane_count+=1)) -lt 10 ]; do + if zellij action dump-screen "$output" && grep "${kak_client}@\[$kak_session\]" "$output" > /dev/null ; then + break; + fi + zellij action focus-next-pane + done + rm -r $(dirname $output) + fi +}} +complete-command -menu zellij-focus client + +## The default behaviour for the `new` command is to open an horizontal pane in a zellij session +alias global focus zellij-focus +alias global terminal zellij-terminal-impl + +} + From f33126c2a98959f7ebb1627c3b0fcdb3b576a7fc Mon Sep 17 00:00:00 2001 From: Bob Qi Date: Wed, 22 Feb 2023 15:57:22 +0800 Subject: [PATCH 3/5] give up to wrap command into a shell to avoid conflict with connect.kak --- rc/windowing/zellij.kak | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/rc/windowing/zellij.kak b/rc/windowing/zellij.kak index f4ef85d0..b1ac6246 100644 --- a/rc/windowing/zellij.kak +++ b/rc/windowing/zellij.kak @@ -13,7 +13,7 @@ declare-option -hidden -docstring %{zellij run options (please check out "zellij define-command -hidden -params .. zellij-run %{ nop %sh{ - zellij run ${kak_opt_zellij_run_options} -- $SHELL -i -c "$*" < /dev/null > /dev/null 2>&1 & + zellij run $kak_opt_zellij_run_options -- "$@" } set global zellij_run_options "" unset buffer zellij_run_options From 02bc786fb7e1c7fbb17ac689241d50d5eb7c7882 Mon Sep 17 00:00:00 2001 From: Bob Qi Date: Fri, 24 Feb 2023 12:21:16 +0800 Subject: [PATCH 4/5] remove the option and provide session name explictly --- rc/windowing/zellij.kak | 27 +++++++++------------------ 1 file changed, 9 insertions(+), 18 deletions(-) diff --git a/rc/windowing/zellij.kak b/rc/windowing/zellij.kak index b1ac6246..e4c672c9 100644 --- a/rc/windowing/zellij.kak +++ b/rc/windowing/zellij.kak @@ -5,24 +5,17 @@ provide-module zellij %{ # ensure we're running under zellij evaluate-commands %sh{ - [ -z "${kak_opt_windowing_modules}" ] || [ -n "$ZELLIJ" ] || echo 'fail zellij not detected' + [ -z "${kak_opt_windowing_modules}" ] || [ -n "$ZELLIJ" -a -n "$ZELLIJ_SESSION_NAME" ] || echo 'fail zellij not detected' } -declare-option -hidden -docstring %{zellij run options (please check out "zellij run --help" for detail)}\ - str zellij_run_options "" - -define-command -hidden -params .. zellij-run %{ - nop %sh{ - zellij run $kak_opt_zellij_run_options -- "$@" - } - set global zellij_run_options "" - unset buffer zellij_run_options - unset window zellij_run_options -} +define-command -hidden -params 2.. zellij-run %{ nop %sh{ + zellij_run_options=$1 + shift + zellij --session "$kak_client_env_ZELLIJ_SESSION_NAME" run $zellij_run_options -- "$@" +}} define-command -hidden -params 1.. zellij-terminal-impl %{ - set global zellij_run_options "--close-on-exit" - zellij-run %arg{@} + zellij-run "--close-on-exit" %arg{@} } complete-command zellij-terminal-impl shell @@ -31,8 +24,7 @@ zellij-terminal-vertical []: create a new terminal as a zel The current pane is split into two, top and bottom The program passed as argument will be executed in the new terminal' \ %{ - set global zellij_run_options "--direction down" - zellij-run %arg{@} + zellij-run "--direction down" %arg{@} } complete-command zellij-terminal-vertical shell @@ -41,8 +33,7 @@ zellij-terminal-horizontal []: create a new terminal as a z The current pane is split into two, left and right The program passed as argument will be executed in the new terminal' \ %{ - set global zellij_run_options "--direction right" - zellij-run %arg{@} + zellij-run "--direction right" %arg{@} } complete-command zellij-terminal-horizontal shell From 4f0334c4761badefed77328cf9d5635c3377eac7 Mon Sep 17 00:00:00 2001 From: Bob Qi Date: Sun, 26 Feb 2023 07:29:11 +0800 Subject: [PATCH 5/5] add zellij-action command --- rc/windowing/zellij.kak | 3 +++ 1 file changed, 3 insertions(+) diff --git a/rc/windowing/zellij.kak b/rc/windowing/zellij.kak index e4c672c9..7aa00849 100644 --- a/rc/windowing/zellij.kak +++ b/rc/windowing/zellij.kak @@ -8,6 +8,9 @@ evaluate-commands %sh{ [ -z "${kak_opt_windowing_modules}" ] || [ -n "$ZELLIJ" -a -n "$ZELLIJ_SESSION_NAME" ] || echo 'fail zellij not detected' } +define-command -params 1.. zellij-action %{ nop %sh{ + zellij --session "$kak_client_env_ZELLIJ_SESSION_NAME" action "$@" +}} define-command -hidden -params 2.. zellij-run %{ nop %sh{ zellij_run_options=$1 shift