Updated kak config

This commit is contained in:
James Dugan 2025-04-26 14:26:50 -06:00
parent a4833bc635
commit c047fe2d55
21 changed files with 766 additions and 62 deletions

16
.config/kak/tools/clipboard.kak Executable file
View file

@ -0,0 +1,16 @@
declare-option str yank_sys_clipboard_cmd %sh{
test "$(uname)" = "Darwin" && echo "pbcopy" || echo "xsel -ib"
}
declare-option str paste_sys_clipboard_cmd %sh{
test "$(uname)" = "Darwin" && echo "pbpaste" || echo "xsel -ob"
}
define-command yank-sys -docstring "yank into the system clipboard" %{
execute-keys -draft "<a-|>%opt{yank_sys_clipboard_cmd}<ret>"
}
define-command paste-sys-before -docstring "paste from the system clipboard before selection" %{
execute-keys -draft "!%opt{paste_sys_clipboard_cmd}<ret>"
}
define-command paste-sys-after -docstring "paste from the system clipboard after selection" %{
execute-keys -draft "<a-!>%opt{paste_sys_clipboard_cmd}<ret>"
}

29
.config/kak/tools/fzf.kak Executable file
View file

@ -0,0 +1,29 @@
# https://junegunn.github.io/fzf
define-command fzf-buflist -docstring "Use fzf to select buffer" %{
set-register f %sh{ printf "%s" "$kak_buflist" | tr ' ' '\n' }
wezterm-terminal-tab sh -c %{
PATH=$PATH:~/.fzf/bin/
kak_session=$1 kak_client=$2 buflist=$3
shift 3
# Note: we need to replace ~ with $HOME here; otherwise bat can't find the file for preview
output=$(printf "$buflist" | sed "s|~|$HOME|" | fzf --preview 'bat --color=always {}')
kak_cmd="evaluate-commands -client $kak_client buffer $output"
echo $kak_cmd | kak -p $kak_session
} -- %val{session} %val{client} %reg{f}
}
define-command fzf-lines -docstring "Use fzf to jump to line in current buffer" %{
set-register f %sh{ mktemp }
execute-keys -draft '%<a-|> nl -b a > $kak_reg_f<ret>'
wezterm-terminal-tab sh -c %{
PATH=$PATH:~/.fzf/bin/
kak_session=$1 kak_client=$2 buffile=$3
shift 3
output=$(fzf --layout=reverse < $buffile)
set -- $output
kak_cmd="evaluate-commands -client $kak_client execute-keys '${1}g'"
rm $buffile
echo $kak_cmd | kak -p $kak_session
} -- %val{session} %val{client} %reg{f}
}

39
.config/kak/tools/kitty.kak Executable file
View file

@ -0,0 +1,39 @@
# https://sw.kovidgoyal.net/kitty
# The following assumes the "splits" layout.
hook global ModuleLoaded kitty %{
define-command kitty-launch-impl -params 3.. %{
nop %sh{
location=$1
type=$2
shift 2
match=""
if [ -n "$kak_client_env_KITTY_WINDOW_ID" ]; then
match="--match=window_id:$kak_client_env_KITTY_WINDOW_ID"
fi
listen=""
if [ -n "$kak_client_env_KITTY_LISTEN_ON" ]; then
listen="--to=$kak_client_env_KITTY_LISTEN_ON"
fi
kitty @ $listen launch --no-response --location=$location --type=$type --cwd="$PWD" $match "$@"
}
} -hidden
define-command kitty-terminal-horizontal -params 1.. %{
kitty-launch-impl "vsplit" "window" %arg{@}
}
complete-command kitty-terminal-horizontal shell
define-command kitty-terminal-vertical -params 1.. %{
kitty-launch-impl "hsplit" "window" %arg{@}
}
complete-command kitty-terminal-vertical shell
define-command kitty-terminal-overlay -params 1.. %{
kitty-launch-impl "default" "overlay" %arg{@}
}
complete-command kitty-terminal-overlay shell
}

View file

@ -1,7 +1,7 @@
# https://github.com/jesseduffield/lazygit
define-command lazygit %{
popup lazygit
kitty-terminal-overlay lazygit
}
alias global lg lazygit

View file

@ -1,9 +1,10 @@
# https://xplr.dev/
# Seriously, xplr is awesome. Get it if you haven't already.
# The reason to use xplr instead of fzf here is sometimes we want to edit a file
# not in the current working directory.
define-command xplr-open -params 1 %{
define-command xplr-open -params 1.. %{
evaluate-commands %sh{
for xplr_file in $1; do
for xplr_file in $@; do
if [ -f "$xplr_file" ]; then
printf "%s\n" "edit $xplr_file"
fi
@ -11,8 +12,16 @@ define-command xplr-open -params 1 %{
}
} -hidden
define-command xplr -params ..1 %{
popup --title open --kak-script %{ xplr-open %opt{popup_output} } -- xplr %arg{@}
define-command xplr -params ..1 -docstring "Use xplr to open file" %{
wezterm-terminal-tab sh -c %{
PATH=$PATH:~/.fzf/bin/
kak_buffile=$1 kak_session=$2 kak_client=$3
shift 3
kak_pwd="${@:-$(dirname "${kak_buffile}")}"
output=$(xplr "${kak_pwd}")
kak_cmd="evaluate-commands -client $kak_client xplr-open $output"
echo $kak_cmd | kak -p $kak_session
} -- %val{buffile} %val{session} %val{client} %arg{@}
}
# Utility command to edit a kak config file with xplr