declare-option str fzf_output ""
declare-option str fzf_open_type ""
define-command -docstring %|Lets you select a file with fzf then open it in a new split, window, or current buffer| \
fzf-file-open %{
set-option global fzf_output %sh[
fd -tf | fzf-tmux -p 60%,80% --style full --border-label "<ret> current window, alt-c new window $kak_session" --margin 1 \
--bind "alt-c:execute-silent(echo 'set-option global fzf_open_type \"new_window\"' | kak -p \"$kak_session\")+accept,\
enter:execute-silent(echo 'set-option global fzf_open_type \"current_window\"' | kak -p \"$kak_session\")+accept,\
alt-b:execute-silent(echo 'set-option global fzf_open_type \"horizontal_split\"' | kak -p \"$kak_session\")+accept,\
alt-v:execute-silent(echo 'set-option global fzf_open_type \"vertical_split\"' | kak -p \"$kak_session\")+accept"
]
hook -once global GlobalSetOption fzf_open_type=.* %{
evaluate-commands %sh{
if [ -z "$kak_opt_fzf_output" ]; then
printf "nop"
elif [ "$kak_opt_fzf_open_type" = "current_window" ]; then
printf "nop %sh{ printf \"edit \'$kak_opt_fzf_output\'\" | kak -p $kak_session}"
elif [ "$kak_opt_fzf_open_type" = "new_window" ]; then
printf "new %{e \'$kak_opt_fzf_output\'}"
elif [ "$kak_opt_fzf_open_type" = "horizontal_split" ]; then
printf "tmux-repl-horizontal 'kak -c $kak_session -e \"edit $kak_opt_fzf_output\"'"
elif [ "$kak_opt_fzf_open_type" = "vertical_split" ]; then
printf "tmux-repl-vertical 'kak -c $kak_session -e \"edit $kak_opt_fzf_output\"'"
fi
}
}
}
map global user f ':fzf-file-open<ret>'
1 Like
nevermind I just used a tempfile instead.
declare-option str fzf_output ""
declare-option str fzf_open_type ""
declare-option str fzf_temp_file ""
define-command -docstring %|Lets you select a file with fzf then open it in a new split, window, or current buffer| \
fzf-file-open %{
evaluate-commands %sh[
temp_file="$(mktemp /tmp/kak-fzf-win.XXX)"
output="$(fd -tf | fzf-tmux -p 60%,80% --style full --border-label "<ret> current window, alt-c new window" --margin 1 \
--bind "alt-c:execute-silent(printf 'set-option global fzf_open_type \"new_window\"' > $temp_file)+accept,\
enter:execute-silent(printf 'set-option global fzf_open_type \"current_window\"' > $temp_file)+accept,\
alt-b:execute-silent(printf 'set-option global fzf_open_type \"horizontal_split\"' > $temp_file)+accept,\
alt-v:execute-silent(printf 'set-option global fzf_open_type \"vertical_split\"' > $temp_file)+accept")"
printf "set-option global fzf_output '$output'\n"
printf "set-option global fzf_temp_file '$temp_file'\n"
if [ -n "$(cat $temp_file)" ]; then
printf "$(cat $temp_file)\n"
fi
rm "$temp_file" > /dev/null
printf "temp file: $temp_file\n" >&2
sleep 0.1
# change this so it uses a temp file to store this data.
]
evaluate-commands %sh{
sleep 0.1
if [ -z "$kak_opt_fzf_output" ]; then
printf "nop"
elif [ "$kak_opt_fzf_open_type" = "current_window" ]; then
printf "edit \'$kak_opt_fzf_output\'"
printf "current_window\n" >&2
elif [ "$kak_opt_fzf_open_type" = "new_window" ]; then
printf "new %{e \'$kak_opt_fzf_output\'}"
printf "new_window\n" >&2
elif [ "$kak_opt_fzf_open_type" = "horizontal_split" ]; then
printf "tmux-repl-horizontal 'kak -c $kak_session -e \"edit $kak_opt_fzf_output\"'"
printf "horizontal\n" >&2
elif [ "$kak_opt_fzf_open_type" = "vertical_split" ]; then
printf "tmux-repl-vertical 'kak -c $kak_session -e \"edit $kak_opt_fzf_output\"'"
printf "vertical\n" >&2
fi
}
}
1 Like