detection.kak (2823B)
1 # Attempt to detect the windowing environment we're operating in 2 # 3 # We try to load modules from the windowing_modules str-list option in order, 4 # stopping when one of the modules loads successfully. This ensures that only 5 # a single module is loaded by default. 6 # 7 # On load each module must attempt to detect the environment it's appropriate 8 # for, and if the environment isn't appropriate it must fail with an error. 9 # In addition, each module must check for the length of the windowing_modules 10 # str-list option defined below, and must /not/ check for an appropriate 11 # environment if the list is empty. An example of this test: 12 # 13 # evaluate-commands %sh{ 14 # [ -z "${kak_opt_windowing_modules}" ] || [ -n "$TMUX" ] || echo 'fail tmux not detected' 15 # } 16 # 17 # Each module is expected to define at least two aliases: 18 # * terminal - create a new terminal with sensible defaults 19 # * focus - focus the specified client, defaulting to the current client 20 # 21 22 declare-option -docstring \ 23 "Ordered list of windowing modules to try and load. An empty list disables 24 both automatic module loading and environment detection, enabling complete 25 manual control of the module loading." \ 26 str-list windowing_modules 'tmux' 'screen' 'zellij' 'wezterm' 'kitty' 'iterm' 'appleterminal' 'sway' 'niri' 'hyprland' 'wayland' 'x11' 27 28 declare-option -docstring %{ 29 windowing module to use in the 'terminal' command 30 } str windowing_module 31 32 declare-option -docstring %{ 33 where to create new windows in the 'terminal' command. 34 35 Possible values: 36 - "window" (default) - new window 37 - "horizontal" - horizontal split (left/right) 38 - "vertical" - vertical split (top/bottom) 39 - "tab" - new tab besides current window 40 } str windowing_placement window 41 42 define-command terminal -params 1.. -docstring %{ 43 terminal <program> [<arguments>]: create a new terminal using the preferred windowing environment and placement 44 45 This executes "%opt{windowing_module}-terminal-%opt{windowing_placement}" with the given arguments. 46 If the windowing module is 'wayland', 'sway' or 'x11', then the 'termcmd' option is used as terminal program. 47 48 Example usage: 49 50 terminal sh 51 evaluate-commands %{ set local windowing_placement horizontal; terminal sh } 52 53 See also the 'new' command. 54 } %{ 55 "%opt{windowing_module}-terminal-%opt{windowing_placement}" %arg{@} 56 } 57 complete-command terminal shell 58 59 hook -group windowing global KakBegin .* %{ 60 evaluate-commands %sh{ 61 set -- ${kak_opt_windowing_modules} 62 if [ $# -gt 0 ]; then 63 echo 'try %{ ' 64 while [ $# -ge 1 ]; do 65 echo "require-module ${1}; set-option global windowing_module ${1} } catch %{ " 66 shift 67 done 68 echo "echo -debug 'no windowing module detected' }" 69 fi 70 } 71 }