From 0319d8769ce7062e7ef05afee8c04a6a7c41705b Mon Sep 17 00:00:00 2001 From: Andrey Orst Date: Mon, 9 Sep 2019 17:02:02 +0300 Subject: [PATCH] add fzf-delete-buffer --- rc/modules/fzf-buffer.kak | 23 ++++++++++++++++++++--- 1 file changed, 20 insertions(+), 3 deletions(-) diff --git a/rc/modules/fzf-buffer.kak b/rc/modules/fzf-buffer.kak index e9f4d0e..37bbe10 100644 --- a/rc/modules/fzf-buffer.kak +++ b/rc/modules/fzf-buffer.kak @@ -11,12 +11,14 @@ hook global ModuleLoaded fzf %§ map global fzf -docstring "open buffer" 'b' ': fzf-buffer' +map global fzf -docstring "open buffer" '' ': fzf-delete-buffer' define-command -hidden fzf-buffer %{ evaluate-commands %sh{ - buffers=$(mktemp ${TMPDIR:-/tmp}/kak-fzf-buffers.XXXXXX) + buffers="" eval "set -- $kak_quoted_buflist" while [ $# -gt 0 ]; do - printf "%s\n" "$1" >> $buffers + buffers="$1 +$buffers" shift done @@ -29,7 +31,22 @@ $kak_opt_fzf_vertical_map: open buffer in vertical split" printf "%s\n" "info -title 'fzf buffer' '$message$tmux_keybindings'" [ ! -z "${kak_client_env_TMUX}" ] && additional_flags="--expect $kak_opt_fzf_vertical_map --expect $kak_opt_fzf_horizontal_map" - printf "%s\n" "fzf -kak-cmd %{buffer} -items-cmd %{(cat $buffers; rm $buffers)} -fzf-args %{--expect $kak_opt_fzf_window_map $additional_flags}" + printf "%s\n" "fzf -kak-cmd %{buffer} -items-cmd %{printf \"%s\n\" \"$buffers\"} -fzf-args %{--expect $kak_opt_fzf_window_map $additional_flags}" +}} + +define-command -hidden fzf-delete-buffer %{ evaluate-commands %sh{ + buffers="" + eval "set -- $kak_quoted_buflist" + while [ $# -gt 0 ]; do + buffers="$1 +$buffers" + shift + done + + message="Delete buffer. +: delete selected buffer." + printf "%s\n" "info -title 'fzf delete-buffer' '$message'" + printf "%s\n" "fzf -kak-cmd %{delete-buffer} -multiple-cmd %{delete-buffer} -items-cmd %{printf \"%s\n\" \"$buffers\"} -fzf-args %{-m --expect $kak_opt_fzf_window_map $additional_flags}" }} §