diff --git a/rc/modules/fzf-yank-ring.kak b/rc/modules/fzf-yank-ring.kak index a170dd5..646615b 100644 --- a/rc/modules/fzf-yank-ring.kak +++ b/rc/modules/fzf-yank-ring.kak @@ -11,19 +11,33 @@ # ╰─────────────────────────────────────╯ try %{ declare-user-mode fzf } -map global fzf -docstring "open yank-ring" 'y' ': fzf-yank-ring' + +# this will fail if yank-ring.kak isn't installed +hook global -once WinCreate .* %{ + try %{ + set-option -add global yank_ring_history + map global fzf -docstring "open yank-ring" 'y' ': fzf-yank-ring' + } +} + +declare-option -hidden str fzf_yank_ring_result define-command -hidden fzf-yank-ring %{ evaluate-commands %sh{ yanks=$(mktemp ${TMPDIR:-/tmp}/kak-fzf-yanks.XXXXXX) eval "set -- $kak_opt_yank_ring_history" while [ $# -gt 0 ]; do - item=$(printf "%s" "$1" | awk 1 ORS='␤') + item=$(printf "%s" "$1" | sed "s/^'//;s/'$//" | awk 1 ORS='␤') printf "%s\n" "$item" >> $yanks shift done - message="Swap between yanks." - - printf "%s\n" "fzf -kak-cmd %{set-register dquote} -items-cmd %{cat $yanks} -filter %{sed 's/␤/\\\\n/g;s/^.//;s/.\\\n$//'}" + message="Swap between items in yank-ring." + printf "%s\n" "fzf -kak-cmd %{set-option global fzf_yank_ring_result} -items-cmd %{cat $yanks} -post-action %{fzf-yank-ring-set-dquote}" }} +define-command fzf-yank-ring-set-dquote %{ + set-register dquote %sh{ + printf "%s\n" "$kak_opt_fzf_yank_ring_result" | sed "s/␤/\n/g;" + } +} +