1
0
Fork 0

fix tmpdir removal

This commit is contained in:
Andrey Orst 2019-03-26 22:21:43 +03:00
parent b2ac9faf9b
commit 29782b25b8

View file

@ -105,7 +105,7 @@ Switches:
-post-action <commands>: Extra commands that are preformed after `-kak-cmd' command. -post-action <commands>: Extra commands that are preformed after `-kak-cmd' command.
-preview-cmd: a preview command -preview-cmd: a preview command
-preview: should fzf window include preview" \ -preview: should fzf window include preview" \
fzf -shell-script-candidates %{echo "-kak-cmd\n-items-cmd\n-fzf-args\n-post-action\n"} -params .. %{ evaluate-commands %sh{ fzf -shell-script-completion %{echo "-kak-cmd\n-items-cmd\n-fzf-args\n-post-action\n"} -params .. %{ evaluate-commands %sh{
while [ $# -gt 0 ]; do while [ $# -gt 0 ]; do
case $1 in case $1 in
-kak-cmd) shift; kakoune_cmd="$1" ;; -kak-cmd) shift; kakoune_cmd="$1" ;;
@ -120,12 +120,15 @@ fzf -shell-script-candidates %{echo "-kak-cmd\n-items-cmd\n-fzf-args\n-post-acti
done done
if [ "${preview}" = "true" ]; then if [ "${preview}" = "true" ]; then
# bake position option to define them at runtime
if [ -n "${kak_client_env_TMUX}" ]; then if [ -n "${kak_client_env_TMUX}" ]; then
# tmux is special case, so it needs to check if current -kak-cmd is `edit'
[ -z "${kakoune_cmd##edit*}" ] && tmux_height="${kak_opt_fzf_file_preview_tmux_height}" [ -z "${kakoune_cmd##edit*}" ] && tmux_height="${kak_opt_fzf_file_preview_tmux_height}"
preview_position="pos=right:${kak_opt_fzf_preview_width};" preview_position="pos=right:${kak_opt_fzf_preview_width};"
else else
preview_position="sleep 0.1; [ \$(tput cols) -gt \$(expr \$(tput lines) \* 2) ] && pos=right:${kak_opt_fzf_preview_width} || pos=top:${kak_opt_fzf_preview_height};" preview_position="sleep 0.1; [ \$(tput cols) -gt \$(expr \$(tput lines) \* 2) ] && pos=right:${kak_opt_fzf_preview_width} || pos=top:${kak_opt_fzf_preview_height};"
fi fi
# handle preview if not defined explicitly
if [ ${kak_opt_fzf_preview} = "true" ] && [ -z "${preview_cmd}" ]; then if [ ${kak_opt_fzf_preview} = "true" ] && [ -z "${preview_cmd}" ]; then
case ${kak_opt_fzf_highlight_cmd} in case ${kak_opt_fzf_highlight_cmd} in
bat) highlight_cmd="bat --color=always --style=plain {}" ;; bat) highlight_cmd="bat --color=always --style=plain {}" ;;
@ -141,6 +144,8 @@ fzf -shell-script-candidates %{echo "-kak-cmd\n-items-cmd\n-fzf-args\n-post-acti
fzf_tmp=$(mktemp -d ${TMPDIR:-/tmp}/fzf.kak.XXXXXX) fzf_tmp=$(mktemp -d ${TMPDIR:-/tmp}/fzf.kak.XXXXXX)
fzfcmd="${fzf_tmp}/fzfcmd" fzfcmd="${fzf_tmp}/fzfcmd"
result="${fzf_tmp}/result" result="${fzf_tmp}/result"
# compose entire fzf command with all args into single file which will be executed later
printf "%s\n" "cd \"${PWD}\" && ${preview_position} ${items_cmd} | SHELL=$(command -v sh) ${kak_opt_fzf_implementation} ${fzf_args} ${preview_cmd} > ${result}; rm ${fzfcmd}" > ${fzfcmd} printf "%s\n" "cd \"${PWD}\" && ${preview_position} ${items_cmd} | SHELL=$(command -v sh) ${kak_opt_fzf_implementation} ${fzf_args} ${preview_cmd} > ${result}; rm ${fzfcmd}" > ${fzfcmd}
chmod 755 ${fzfcmd} chmod 755 ${fzfcmd}
@ -164,8 +169,7 @@ fzf -shell-script-candidates %{echo "-kak-cmd\n-items-cmd\n-fzf-args\n-post-acti
ctrl-w) wincmd="fzf-window" ;; ctrl-w) wincmd="fzf-window" ;;
ctrl-s) wincmd="fzf-vertical" ;; ctrl-s) wincmd="fzf-vertical" ;;
ctrl-v) wincmd="fzf-horizontal" ;; ctrl-v) wincmd="fzf-horizontal" ;;
*) *) if [ -n "${action}" ]; then
if [ -n "${action}" ]; then
printf "%s\n" "evaluate-commands -client ${kak_client} '${kakoune_cmd}' '${action}'" | kak -p ${kak_session} printf "%s\n" "evaluate-commands -client ${kak_client} '${kakoune_cmd}' '${action}'" | kak -p ${kak_session}
[ -n "${post_action}" ] && printf "%s\n" "evaluate-commands -client ${kak_client} ${post_action}" | kak -p ${kak_session} [ -n "${post_action}" ] && printf "%s\n" "evaluate-commands -client ${kak_client} ${post_action}" | kak -p ${kak_session}
fi ;; fi ;;
@ -176,6 +180,6 @@ fzf -shell-script-candidates %{echo "-kak-cmd\n-items-cmd\n-fzf-args\n-post-acti
done done
) < ${result} ) < ${result}
fi fi
rm ${fzf_tmp} rm -rf ${fzf_tmp}
) > /dev/null 2>&1 < /dev/null & ) > /dev/null 2>&1 < /dev/null &
}} }}