1753158041824033875

· ficd's pastes · raw

expires: 2025-10-20

 1provide-module clipboard %~
 2declare-option -docstring %{
 3    Command for copying to system clipboard.
 4} str clipboard_copy_cmd 'wl-copy'
 5
 6declare-option int clip_selcount 0
 7
 8define-command -hidden clip-trim %{
 9    try %{
10        execute-keys <a-k>\n<ret>
11        execute-keys bjGjd
12    }
13}
14
15define-command -docstring %{
16    clip-copy [-split]: copy selections to system clipboard
17        Set the clipboard_copy_cmd option to change the command
18    Switches:
19        -split  ensure each selection separated by newline
20} -params 0..1 clipboard-copy %{
21    # preserve registers
22    evaluate-commands -save-regs 'a|' %{
23        set-option local clip_selcount %val{selection_count}
24        # copy selections
25        execute-keys '"ay'
26        # set shell register to copy command
27        set-register | %opt{clipboard_copy_cmd}
28        # branch based on switch
29        execute-keys %sh{
30            if [ "$kak_opt_clip_selcount" -gt 1 ]; then
31                echo ': edit -scratch<ret>'
32                if [ ${#} = 1 ] && [ ${1} = '-split' ]; then
33                    # paste all
34                    # reduce selections to those without newline
35                    # append a newline
36                    # delete extra newlines
37                    # select all, pipe to copy cmd
38                    echo '"a<a-P><a-K>\n<ret>a<ret><esc>'
39                    echo 'gj: clip-trim<ret>'
40                    echo '%<a-|><ret>'
41                else
42                    # paste all, select all, pipe to copy cmd
43                    echo '"a<a-P>%<a-|><ret>'
44                fi
45                echo ": delete-buffer<ret>"
46            else
47                echo '<a-|><ret>'
48            fi
49        }
50    }
51}
52
53map -docstring "yank the selections into the clipboard" global user y ": clipboard-copy<ret>"
54map -docstring "yank the split selections into the clipboard" global user Y ": clipboard-copy -split<ret>"
55
56map -docstring "paste the clipboard" global user p "<a-!> wl-paste -n<ret>"
57map -docstring "paste the clipboard before" global user P "! wl-paste -n<ret>"
58map -docstring "replace with the clipboard" global user R '"_d! wl-paste  -n<ret>'
59~