kakoune/rc/extra/kitty.kak
Olivier Perret c8403624a7 Expose a 'terminal' command for the various windowing systems
It allows plugins to create generic terminal using the user's preferred windowing system
For example, it can be used to run fzf, gdb or simply a shell.

* 'new' commands are refactored to simply use the 'terminal' one
* style and docstrings has been unified
* all windowing systems go through "sh -c" for consistency purposes, even if unnecessary
2018-12-22 09:36:34 +01:00

82 lines
2.9 KiB
Plaintext

declare-option -docstring %{window type that kitty creates on new and repl calls (kitty|os)} str kitty_window_type kitty
hook -group kitty-hooks global KakBegin .* %sh{
if [ "$TERM" = "xterm-kitty" ] && [ -z "$TMUX" ]; then
echo "
alias global new kitty-new
alias global new-tab kitty-new-tab
alias global terminal kitty-terminal
alias global terminal-tab kitty-terminal-tab
alias global focus kitty-focus
alias global repl kitty-repl
alias global send-text kitty-send-text
"
fi
}
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{
kitty @ new-window --no-response --window-type $kak_opt_kitty_window_type sh -c "$*"
}
}
define-command kitty-new -params .. -command-completion -docstring '
kitty-new [<commands>]: create a new kakoune client as a kitty window
The optional arguments are passed as commands to the new client' \
%{
kitty-terminal "kak -c %val{session} -e '%arg{@}'"
}
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{
kitty @ new-window --no-response --new-tab sh -c "$*"
}
}
define-command kitty-new-tab -params .. -command-completion -docstring '
kitty-new-tab <program> [<arguments>]: create a new terminal as kitty tab
The optional arguments are passed as commands to the new client' \
%{
kitty-terminal-tab "kak -c %val{session} -e '%arg{@}'"
}
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
kitty @ focus-tab --no-response -m=id:$kak_client_env_KITTY_WINDOW_ID
kitty @ focus-window --no-response -m=id:$kak_client_env_KITTY_WINDOW_ID
fi
}
}
define-command kitty-repl -params .. -shell-completion -docstring '
kitty-repl [<arguments>]: create a new window for repl interaction
All optional parameters are forwarded to the new window' \
%{
nop %sh{
if [ $# -eq 0 ]; then
cmd="${SHELL:-/bin/sh}"
else
cmd="$*"
fi
kitty @ new-window --no-response --window-type $kak_opt_kitty_window_type --title kak_repl_window --cwd "$PWD" $cmd < /dev/null > /dev/null 2>&1 &
}
}
define-command kitty-send-text -docstring "send the selected text to the repl window" %{
nop %sh{
kitty @ send-text -m=title:kak_repl_window "${kak_selection}"
}
}