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\nagjd%' else # paste all, select all, pipe to copy cmd echo '"a%' fi } # clean up delete-buffer } } map -docstring "yank the selections into the clipboard" global user y ": clipboard-copy" map -docstring "yank the split selections into the clipboard" global user Y ": clipboard-copy -split" map -docstring "paste the clipboard" global user p " wl-paste -n" map -docstring "paste the clipboard before" global user P "! wl-paste -n" map -docstring "replace with the clipboard" global user R '"_d! wl-paste -n'