52 lines
1.9 KiB
Text
52 lines
1.9 KiB
Text
declare-option -docstring %{
|
|
Command for copying to system clipboard.
|
|
} str clipboard_copy_cmd 'wl-copy'
|
|
|
|
declare-option int clip_selcount 0
|
|
|
|
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|' %{
|
|
set-option local clip_selcount %val{selection_count}
|
|
# 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 [ "$kak_opt_clip_selcount" -gt 1 ]; then
|
|
if [ ${#} = 1 ] && [ ${1} = '-split' ]; then
|
|
# paste all
|
|
# reduce selections to those without newline
|
|
# append a newline
|
|
# delete extra newlines
|
|
# select all, pipe to copy cmd
|
|
echo '"a<a-P><a-K>\n<ret>a<ret><esc>gjd%<a-|><ret>'
|
|
printf 'gj:try %%{ exec <a-k>\\n<ret> }'
|
|
else
|
|
# paste all, select all, pipe to copy cmd
|
|
echo '"a<a-P>%<a-|><ret>'
|
|
fi
|
|
else
|
|
echo '<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>'
|
|
|