59 lines
2.1 KiB
Text
59 lines
2.1 KiB
Text
provide-module clipboard %~
|
|
declare-option -docstring %{
|
|
Command for copying to system clipboard.
|
|
} str clipboard_copy_cmd 'wl-copy'
|
|
|
|
declare-option int clip_selcount 0
|
|
|
|
define-command -hidden clip-trim %{
|
|
try %{
|
|
execute-keys <a-k>\n<ret>
|
|
execute-keys bjGjd
|
|
}
|
|
}
|
|
|
|
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'
|
|
# 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
|
|
echo ': edit -scratch<ret>'
|
|
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>'
|
|
echo 'gj: clip-trim<ret>'
|
|
echo '%<a-|><ret>'
|
|
else
|
|
# paste all, select all, pipe to copy cmd
|
|
echo '"a<a-P>%<a-|><ret>'
|
|
fi
|
|
echo ": delete-buffer<ret>"
|
|
else
|
|
echo '<a-|><ret>'
|
|
fi
|
|
}
|
|
}
|
|
}
|
|
|
|
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>'
|
|
~
|