use kitty launch command, make commands consistent

`new-window` is a legacy command (see https://github.com/kovidgoyal/kitty/issues/2708).
`KITTY_WINDOW_ID` should be set for any kitty window anyways.
This commit is contained in:
basbebe 2021-03-04 20:22:59 +01:00
parent 66dddc0d67
commit 8d5d0d7d90
No known key found for this signature in database
GPG Key ID: 1E18AD713D17B254

View File

@ -8,23 +8,24 @@ evaluate-commands %sh{
[ -z "${kak_opt_windowing_modules}" ] || [ "$TERM" = "xterm-kitty" ] || echo 'fail Kitty not detected' [ -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 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.. -shell-completion -docstring ' define-command kitty-terminal -params 1.. -shell-completion -docstring '
kitty-terminal <program> [<arguments>]: create a new terminal as a kitty window kitty-terminal <program> [<arguments>]: create a new terminal as a kitty window
The program passed as argument will be executed in the new terminal' \ The program passed as argument will be executed in the new terminal' \
%{ %{
nop %sh{ nop %sh{
local match="" match=""
if [ -n "$kak_client_env_KITTY_WINDOW_ID" ]; then if [ -n "$kak_client_env_KITTY_WINDOW_ID" ]; then
match="--match=id:$kak_client_env_KITTY_WINDOW_ID" match="--match=id:$kak_client_env_KITTY_WINDOW_ID"
fi fi
if [ -z "$kak_client_env_KITTY_LISTEN_ON" ]; then listen=""
kitty @ new-window --no-response --window-type "$kak_opt_kitty_window_type" --cwd "$PWD" $match "$@" if [ -n "$kak_client_env_KITTY_LISTEN_ON" ]; then
else listen="--to=$kak_client_env_KITTY_LISTEN_ON"
kitty @ --to "$kak_client_env_KITTY_LISTEN_ON" new-window --no-response --window-type "$kak_opt_kitty_window_type" --cwd "$PWD" $match "$@"
fi fi
kitty @ $listen launch --no-response --type="$kak_opt_kitty_window_type" --cwd="$PWD" $match "$@"
} }
} }
@ -33,16 +34,17 @@ kitty-terminal-tab <program> [<arguments>]: create a new terminal as kitty tab
The program passed as argument will be executed in the new terminal' \ The program passed as argument will be executed in the new terminal' \
%{ %{
nop %sh{ nop %sh{
local match="" match=""
if [ -n "$kak_client_env_KITTY_WINDOW_ID" ]; then if [ -n "$kak_client_env_KITTY_WINDOW_ID" ]; then
match="--match=id:$kak_client_env_KITTY_WINDOW_ID" match="--match=id:$kak_client_env_KITTY_WINDOW_ID"
fi fi
if [ -z "$kak_client_env_KITTY_LISTEN_ON" ]; then listen=""
kitty @ new-window --no-response --new-tab --cwd "$PWD" $match "$@" if [ -n "$kak_client_env_KITTY_LISTEN_ON" ]; then
else listen="--to=$kak_client_env_KITTY_LISTEN_ON"
kitty @ --to "$kak_client_env_KITTY_LISTEN_ON" new-window --no-response --new-tab --cwd "$PWD" $match "$@"
fi fi
kitty @ $listen launch --no-response --type=tab --cwd="$PWD" $match "$@"
} }
} }
@ -54,13 +56,17 @@ If no client is passed then the current one is used' \
if [ $# -eq 1 ]; then if [ $# -eq 1 ]; then
printf "evaluate-commands -client '%s' focus" "$1" printf "evaluate-commands -client '%s' focus" "$1"
else else
if [ -z "$kak_client_env_KITTY_LISTEN_ON" ]; then match=""
kitty @ focus-tab --no-response --match=id:$kak_client_env_KITTY_WINDOW_ID if [ -n "$kak_client_env_KITTY_WINDOW_ID" ]; then
kitty @ focus-window --no-response --match=id:$kak_client_env_KITTY_WINDOW_ID match="--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
listen=""
if [ -n "$kak_client_env_KITTY_LISTEN_ON" ]; then
listen="--to=$kak_client_env_KITTY_LISTEN_ON"
fi
kitty @ $listen focus-window --no-response $match
fi fi
} }
} }