kakoune/rc/windowing/kitty.kak
Maxime Coste bdee3abd88 Match on kitty window id when available
This ensures new window are created in the same os window as the
current client instead of the default one.

Closes #4009
2021-03-01 08:47:09 +11:00

73 lines
2.9 KiB
Plaintext

# https://sw.kovidgoyal.net/kitty/index.html
# ‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾
provide-module kitty %{
# ensure that we're running on kitty
evaluate-commands %sh{
[ -z "${kak_opt_windowing_modules}" ] || [ "$TERM" = "xterm-kitty" ] || echo 'fail Kitty not detected'
}
declare-option -docstring %{window type that kitty creates on new and repl calls (kitty|os)} str kitty_window_type kitty
define-command kitty-terminal -params 1.. -shell-completion -docstring '
kitty-terminal <program> [<arguments>]: create a new terminal as a kitty window
The program passed as argument will be executed in the new terminal' \
%{
nop %sh{
local match=""
if [ -n "$kak_client_env_KITTY_WINDOW_ID" ]; then
match="--match=id:$kak_client_env_KITTY_WINDOW_ID"
fi
if [ -z "$kak_client_env_KITTY_LISTEN_ON" ]; then
kitty @ new-window --no-response --window-type "$kak_opt_kitty_window_type" --cwd "$PWD" $match "$@"
else
kitty @ --to "$kak_client_env_KITTY_LISTEN_ON" new-window --no-response --window-type "$kak_opt_kitty_window_type" --cwd "$PWD" $match "$@"
fi
}
}
define-command kitty-terminal-tab -params 1.. -shell-completion -docstring '
kitty-terminal-tab <program> [<arguments>]: create a new terminal as kitty tab
The program passed as argument will be executed in the new terminal' \
%{
nop %sh{
local match=""
if [ -n "$kak_client_env_KITTY_WINDOW_ID" ]; then
match="--match=id:$kak_client_env_KITTY_WINDOW_ID"
fi
if [ -z "$kak_client_env_KITTY_LISTEN_ON" ]; then
kitty @ new-window --no-response --new-tab --cwd "$PWD" $match "$@"
else
kitty @ --to "$kak_client_env_KITTY_LISTEN_ON" new-window --no-response --new-tab --cwd "$PWD" $match "$@"
fi
}
}
define-command kitty-focus -params ..1 -client-completion -docstring '
kitty-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"
else
if [ -z "$kak_client_env_KITTY_LISTEN_ON" ]; then
kitty @ focus-tab --no-response --match=id:$kak_client_env_KITTY_WINDOW_ID
kitty @ focus-window --no-response --match=id:$kak_client_env_KITTY_WINDOW_ID
else
kitty @ --to "$kak_client_env_KITTY_LISTEN_ON" focus-tab --no-response --match=id:$kak_client_env_KITTY_WINDOW_ID
kitty @ --to "$kak_client_env_KITTY_LISTEN_ON" focus-window --no-response --match=id:$kak_client_env_KITTY_WINDOW_ID
fi
fi
}
}
alias global terminal kitty-terminal
alias global terminal-tab kitty-terminal-tab
alias global focus kitty-focus
}