kakoune/rc/windowing/zellij.kak
Johannes Altmanninger 746e0d032f rc windowing: allow to configure windowing system and window placement in new/terminal commands
Today I can control "terminal" and "new" by changing the terminal
alias but I always need to choose a concrete implementation, like
"tmux-terminal-horizontal", even when there is otherwise no need to
mention tmux in my config.

Allow to configure windowing system and window placement independently
by introducing dedicated options.

This allows to create mappings that work in any windowing system like

	map global user c   %{:with-option windowing_placement window new<ret>}
	map global user '"' %{:with-option windowing_placement vertical new<ret>}
	map global user '%' %{:with-option windowing_placement horizontal new<ret>}

For windowing systems that don't support all placements, you can wrap
the above in try/catch to fall back on the "window" variant which is
defined for all windowing systems.

When using multiple (nested) windowing systems, you might want to
add mappings like

	map global user t %{:with-option windowing_module tmux new<ret>}
	map global user T %{:with-option windowing_module wayland new<ret>}

---

This changes the default "terminal" alias for some modules. In
particular, instead of delegating to

    iterm-terminal-vertical
    screen-terminal-vertical
    tmux-terminal-horizontal
    wezterm-terminal-vertical

it will now by default delegate to the respective "-window" variant.
We could maintain backwards compatiblity here by setting the
"windowing_placement" option accordingly, but the new behavior seems
more logical?

Also, this removes the "terminal-tab" alias which was only defined
by the kitty module.

We could try to keep the alias approach and implement a "with-alias"
command, however that approach can only capture both dimensions
(windowing system and placement) if we add tons of commands
like "terminal-horizontal" (with implied windowing system) and
"tmux-terminal" (with implied placement).

Side thought: we could also get rid of the "focus" alias and instead
define

    define-command focus %{
        "%opt{windowing_module}-focus"
    }

Closes #3943, #4425
2023-11-13 22:54:49 +01:00

68 lines
2.4 KiB
Plaintext

# https://zellij.dev/
# ‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾
provide-module zellij %{
# ensure we're running under zellij
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
zellij --session "$kak_client_env_ZELLIJ_SESSION_NAME" run $zellij_run_options -- "$@"
}}
define-command -hidden -params 1.. zellij-terminal-window %{
zellij-run "--close-on-exit" %arg{@}
}
complete-command zellij-terminal-window shell
define-command zellij-terminal-vertical -params 1.. -docstring '
zellij-terminal-vertical <program> [<arguments>]: 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' \
%{
zellij-run "--direction down" %arg{@}
}
complete-command zellij-terminal-vertical shell
define-command zellij-terminal-horizontal -params 1.. -docstring '
zellij-terminal-horizontal <program> [<arguments>]: 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' \
%{
zellij-run "--direction right" %arg{@}
}
complete-command zellij-terminal-horizontal shell
define-command zellij-focus -params ..1 -docstring '
zellij-focus [<client>]: 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
}