1
0
Fork 0

Merge pull request #54 from andreyorst/fix-yank-ring

Fix yank ring
This commit is contained in:
Andrey Orst 2019-04-08 11:25:54 +03:00 committed by GitHub
commit 78b1314fa9
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -11,19 +11,33 @@
# ╰─────────────────────────────────────╯
try %{ declare-user-mode fzf }
map global fzf -docstring "open yank-ring" 'y' '<esc>: fzf-yank-ring<ret>'
# 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' '<esc>: fzf-yank-ring<ret>'
}
}
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" "fzf -kak-cmd %{set-register dquote} -items-cmd %{cat $yanks} -filter %{sed \"s/␤/\\\n/g;s/^'|'$//\"}"
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;"
}
}