diff --git a/rc/windowing/detection.kak b/rc/windowing/detection.kak index 08867c80..a3af2349 100644 --- a/rc/windowing/detection.kak +++ b/rc/windowing/detection.kak @@ -25,14 +25,62 @@ both automatic module loading and environment detection, enabling complete manual control of the module loading." \ str-list windowing_modules 'tmux' 'screen' 'zellij' 'kitty' 'iterm' 'sway' 'wayland' 'x11' 'wezterm' -hook -group windowing global KakBegin .* %{ +declare-option -docstring %{ + windowing module to use in the 'terminal' command +} str windowing_module +declare-option -docstring %{ + where to create new windows in the 'terminal' command. + + Possible values: + - "window" (default) - new window + - "horizontal" - horizontal split (left/right) + - "vertical" - vertical split (top/bottom) + - "tab" - new tab besides current window +} str windowing_placement window + +define-command terminal -params 1.. -docstring %{ + terminal []: create a new terminal using the preferred windowing environment and placement + + This executes "%opt{windowing_module}-terminal-%opt{windowing_placement}" with the given arguments. + If the windowing module is 'wayland', 'sway' or 'x11', then the 'termcmd' option is used as terminal program. + + Example usage: + + terminal sh + with-option windowing_placement horizontal terminal sh + + See also the 'new' command. +} %{ + "%opt{windowing_module}-terminal-%opt{windowing_placement}" %arg{@} +} +complete-command terminal shell + +# TODO Move this? +define-command with-option -params 3.. -docstring %{ + with-option []: evaluate a command with a modified option +} %{ + evaluate-commands -save-regs s %{ + evaluate-commands set-register s %exp{%%opt{%arg{1}}} + set-option current %arg{1} %arg{2} + evaluate-commands %sh{ + shift 2 + for arg + do + printf "'%s' " "$(printf %s "$arg" | sed "s/'/''/g")" + done + } + set-option current %arg{1} %reg{s} + } +} + +hook -group windowing global KakBegin .* %{ evaluate-commands %sh{ set -- ${kak_opt_windowing_modules} if [ $# -gt 0 ]; then echo 'try %{ ' while [ $# -ge 1 ]; do - echo "require-module ${1} } catch %{ " + echo "require-module ${1}; set-option global windowing_module ${1} } catch %{ " shift done echo "echo -debug 'no windowing module detected' }" diff --git a/rc/windowing/iterm.kak b/rc/windowing/iterm.kak index 1959603f..2ca46dfb 100644 --- a/rc/windowing/iterm.kak +++ b/rc/windowing/iterm.kak @@ -120,6 +120,5 @@ If no client is passed then the current one is used' \ complete-command -menu iterm-focus client alias global focus iterm-focus -alias global terminal iterm-terminal-vertical } diff --git a/rc/windowing/kitty.kak b/rc/windowing/kitty.kak index 6f69aa9f..a81f969d 100644 --- a/rc/windowing/kitty.kak +++ b/rc/windowing/kitty.kak @@ -10,8 +10,8 @@ evaluate-commands %sh{ declare-option -docstring %{window type that kitty creates on new and repl calls (window|os-window)} str kitty_window_type window -define-command kitty-terminal -params 1.. -docstring ' -kitty-terminal []: create a new terminal as a kitty window +define-command kitty-terminal-window -params 1.. -docstring ' +kitty-terminal-window []: create a new terminal as a kitty window The program passed as argument will be executed in the new terminal' \ %{ nop %sh{ @@ -28,7 +28,7 @@ The program passed as argument will be executed in the new terminal' \ kitty @ $listen launch --no-response --type="$kak_opt_kitty_window_type" --cwd="$PWD" $match "$@" } } -complete-command kitty-terminal shell +complete-command kitty-terminal-window shell define-command kitty-terminal-tab -params 1.. -docstring ' kitty-terminal-tab []: create a new terminal as kitty tab @@ -74,8 +74,11 @@ If no client is passed then the current one is used' \ } complete-command -menu kitty-focus client -alias global terminal kitty-terminal -alias global terminal-tab kitty-terminal-tab alias global focus kitty-focus +# deprecated +define-command -hidden kitty-terminal -params 1.. %{ + kitty-terminal-window %arg{@} +} + } diff --git a/rc/windowing/new-client.kak b/rc/windowing/new-client.kak index 214a18e3..f852b395 100644 --- a/rc/windowing/new-client.kak +++ b/rc/windowing/new-client.kak @@ -1,6 +1,6 @@ define-command new -params .. -docstring ' new []: create a new Kakoune client -The ''terminal'' alias is being used to determine the user''s preferred terminal emulator +The ''terminal'' command is used to determine the user''s preferred terminal emulator The optional arguments are passed as commands to the new client' \ %{ terminal kak -c %val{session} -e "%arg{@}" diff --git a/rc/windowing/repl/x11.kak b/rc/windowing/repl/x11.kak index 0c37e994..8f048a74 100644 --- a/rc/windowing/repl/x11.kak +++ b/rc/windowing/repl/x11.kak @@ -11,7 +11,7 @@ define-command -docstring %{ All optional parameters are forwarded to the new window } \ -params .. \ - x11-repl %{ x11-terminal sh -c %{ + x11-repl %{ x11-terminal-window sh -c %{ winid="${WINDOWID:-$(xdotool search --pid ${PPID} | tail -1)}" printf "evaluate-commands -try-client $1 \ 'set-option current x11_repl_id ${winid}'" | kak -p "$2" diff --git a/rc/windowing/screen.kak b/rc/windowing/screen.kak index b59b7588..d5515c99 100644 --- a/rc/windowing/screen.kak +++ b/rc/windowing/screen.kak @@ -25,7 +25,7 @@ define-command screen-terminal-impl -hidden -params 3.. %{ } define-command screen-terminal-vertical -params 1.. -docstring ' -screen-terminal-vertical [] []: create a new terminal as a screen pane +screen-terminal-vertical []: create a new terminal as a screen pane The current pane is split into two, left and right The program passed as argument will be executed in the new terminal' \ %{ @@ -71,6 +71,5 @@ If no client is passed then the current one is used' \ complete-command -menu screen-focus client alias global focus screen-focus -alias global terminal screen-terminal-vertical } diff --git a/rc/windowing/sway.kak b/rc/windowing/sway.kak index 4df12240..c4501c29 100644 --- a/rc/windowing/sway.kak +++ b/rc/windowing/sway.kak @@ -9,6 +9,37 @@ evaluate-commands %sh{ require-module 'wayland' +alias global sway-terminal-window wayland-terminal-window + +define-command sway-terminal-vertical -params 1.. -docstring ' + sway-terminal-vertical []: create a new terminal as a Sway window + The current pane is split into two, top and bottom + The program passed as argument will be executed in the new terminal' \ +%{ + nop %sh{swaymsg split vertical} + wayland-terminal-window %arg{@} +} +complete-command sway-terminal-vertical shell + +define-command sway-terminal-horizontal -params 1.. -docstring ' + sway-terminal-horizontal []: create a new terminal as a Sway window + The current pane is split into two, left and right + The program passed as argument will be executed in the new terminal' \ +%{ + nop %sh{swaymsg split horizontal} + wayland-terminal-window %arg{@} +} +complete-command sway-terminal-horizontal shell + +define-command sway-terminal-tab -params 1.. -docstring ' + sway-terminal-tab []: create a new terminal as a Sway window + The program passed as argument will be executed in the new terminal' \ +%{ + nop %sh{swaymsg 'split horizontal; layout tabbed'} + wayland-terminal-window %arg{@} +} +complete-command sway-terminal-tab shell + define-command sway-focus-pid -hidden %{ evaluate-commands %sh{ pid=$kak_client_pid @@ -45,7 +76,6 @@ If no client is passed, then the current client is used' \ } complete-command -menu sway-focus client -unalias global focus alias global focus sway-focus } diff --git a/rc/windowing/tmux.kak b/rc/windowing/tmux.kak index a433692c..ab0743c7 100644 --- a/rc/windowing/tmux.kak +++ b/rc/windowing/tmux.kak @@ -52,7 +52,7 @@ The program passed as argument will be executed in the new terminal' \ complete-command tmux-terminal-horizontal shell define-command tmux-terminal-window -params 1.. -docstring ' -tmux-terminal-window [] []: create a new terminal as a tmux window +tmux-terminal-window []: create a new terminal as a tmux window The program passed as argument will be executed in the new terminal' \ %{ tmux-terminal-impl 'new-window' %arg{@} @@ -78,6 +78,5 @@ complete-command -menu tmux-focus client ## The default behaviour for the `new` command is to open an horizontal pane in a tmux session alias global focus tmux-focus -alias global terminal tmux-terminal-horizontal } diff --git a/rc/windowing/wayland.kak b/rc/windowing/wayland.kak index 17654f6a..33737f7f 100644 --- a/rc/windowing/wayland.kak +++ b/rc/windowing/wayland.kak @@ -28,8 +28,8 @@ A shell command is appended to the one set in this option at runtime} \ done } -define-command wayland-terminal -params 1.. -docstring ' -wayland-terminal []: create a new terminal as a Wayland window +define-command wayland-terminal-window -params 1.. -docstring ' +wayland-terminal-window []: create a new terminal as a Wayland window The program passed as argument will be executed in the new terminal' \ %{ evaluate-commands -save-regs 'a' %{ @@ -46,7 +46,7 @@ The program passed as argument will be executed in the new terminal' \ } } } -complete-command wayland-terminal shell +complete-command wayland-terminal-window shell define-command wayland-focus -params ..1 -docstring ' wayland-focus []: focus a given client''s window @@ -57,6 +57,10 @@ If no client is passed, then the current client is used' \ complete-command -menu wayland-focus client alias global focus wayland-focus -alias global terminal wayland-terminal + +# deprecated +define-command -hidden wayland-terminal -params 1.. %{ + wayland-terminal-window %arg{@} +} } diff --git a/rc/windowing/wezterm.kak b/rc/windowing/wezterm.kak index 4db0ea84..befdc11a 100644 --- a/rc/windowing/wezterm.kak +++ b/rc/windowing/wezterm.kak @@ -16,7 +16,7 @@ define-command wezterm-terminal-impl -hidden -params 2.. %{ } define-command wezterm-terminal-vertical -params 1.. -docstring ' -wezterm-terminal-vertical [] []: create a new terminal as a wezterm pane +wezterm-terminal-vertical []: create a new terminal as a wezterm pane The current pane is split into two, top and bottom The program passed as argument will be executed in the new terminal' \ %{ @@ -66,6 +66,5 @@ If no client is passed then the current one is used' \ complete-command -menu wezterm-focus client alias global focus wezterm-focus -alias global terminal wezterm-terminal-vertical } diff --git a/rc/windowing/x11.kak b/rc/windowing/x11.kak index c92972a7..f65718b1 100644 --- a/rc/windowing/x11.kak +++ b/rc/windowing/x11.kak @@ -33,8 +33,8 @@ A shell command is appended to the one set in this option at runtime} \ done } -define-command x11-terminal -params 1.. -docstring ' -x11-terminal []: create a new terminal as an X11 window +define-command x11-terminal-window -params 1.. -docstring ' +x11-terminal-window []: create a new terminal as an X11 window The program passed as argument will be executed in the new terminal' \ %{ evaluate-commands -save-regs 'a' %{ @@ -51,7 +51,7 @@ The program passed as argument will be executed in the new terminal' \ } } } -complete-command x11-terminal shell +complete-command x11-terminal-window shell define-command x11-focus -params ..1 -docstring ' x11-focus []: focus a given client''s window @@ -69,6 +69,10 @@ If no client is passed, then the current client is used' \ complete-command -menu x11-focus client alias global focus x11-focus -alias global terminal x11-terminal + +# deprecated +define-command -hidden x11-terminal -params 1.. %{ + x11-terminal-window %arg{@} +} } diff --git a/rc/windowing/zellij.kak b/rc/windowing/zellij.kak index 7aa00849..71f962ec 100644 --- a/rc/windowing/zellij.kak +++ b/rc/windowing/zellij.kak @@ -17,10 +17,10 @@ define-command -hidden -params 2.. zellij-run %{ nop %sh{ zellij --session "$kak_client_env_ZELLIJ_SESSION_NAME" run $zellij_run_options -- "$@" }} -define-command -hidden -params 1.. zellij-terminal-impl %{ +define-command -hidden -params 1.. zellij-terminal-window %{ zellij-run "--close-on-exit" %arg{@} } -complete-command zellij-terminal-impl shell +complete-command zellij-terminal-window shell define-command zellij-terminal-vertical -params 1.. -docstring ' zellij-terminal-vertical []: create a new terminal as a zellij pane @@ -62,7 +62,6 @@ 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 }