dotfiles/.config/kak/autoload/clipboard.kak

44 lines
1.6 KiB
Text

declare-option -docstring %{
Command for copying to system clipboard.
} str clipboard_copy_cmd 'wl-copy'
define-command -docstring %{
clip-copy [-split]: copy selections to system clipboard
Set the clipboard_copy_cmd option to change the command
Switches:
-split ensure each selection separated by newline
} -params 0..1 clipboard-copy %{
# preserve registers
evaluate-commands -save-regs 'a|' %{
# copy selections
execute-keys '"ay'
# disposable buffer
edit -scratch
# set shell register to copy command
set-register | %opt{clipboard_copy_cmd}
# branch based on switch
execute-keys %sh{
if [ ${#} = 1 ] && [ ${1} = '-split' ]; then
# paste all
# reduce selections to those without newline
# append a newline
# delete trailing newline
# select all, pipe to copy cmd
echo '"a<a-P><a-K>\n<ret>a<ret><esc>gjd%<a-|><ret>'
else
# paste all, select all, pipe to copy cmd
echo '"a<a-P>%<a-|><ret>'
fi
}
# clean up
delete-buffer
}
}
map -docstring "yank the selections into the clipboard" global user y ": clipboard-copy<ret>"
map -docstring "yank the split selections into the clipboard" global user Y ": clipboard-copy -split<ret>"
map -docstring "paste the clipboard" global user p "<a-!> wl-paste -n<ret>"
map -docstring "paste the clipboard before" global user P "! wl-paste -n<ret>"
map -docstring "replace with the clipboard" global user R '"_d! wl-paste -n<ret>'