diff --git a/.config/kak/autoload/clipboard.kak b/.config/kak/autoload/clipboard.kak index ab4d788b..7bd91ca8 100644 --- a/.config/kak/autoload/clipboard.kak +++ b/.config/kak/autoload/clipboard.kak @@ -2,6 +2,8 @@ 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 @@ -10,6 +12,7 @@ define-command -docstring %{ } -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 @@ -18,16 +21,21 @@ define-command -docstring %{ 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%' + 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\nagjd%' + printf 'gj:try %%{ exec \\n }' + else + # paste all, select all, pipe to copy cmd + echo '"a%' + fi else - # paste all, select all, pipe to copy cmd - echo '"a%' + echo '' fi } # clean up