1
0
Fork 0

make cd separate simplified funtion

This commit is contained in:
Andrey Orst 2018-11-22 15:36:32 +03:00
parent 1652f92b72
commit 72fd5719a5

View file

@ -17,15 +17,48 @@ str fzf_cd_command "find"
map global fzf -docstring "change directory" 'c' '<esc>: fzf-cd<ret>'
define-command -hidden fzf-cd %{ evaluate-commands %sh{
title="fzf change directory"
message="Change the server''s working directory"
echo "info -title '$title' '$message'"
printf '%s\n' "info -title %{fzf change directory} %{Change the server's working directory}"
case $kak_opt_fzf_cd_command in
find)
cmd="(echo .. && find \( -path '*/.svn*' -o -path '*/.git*' \) -prune -o -type d -print)" ;;
items_command="(echo .. && find \( -path '*/.svn*' -o -path '*/.git*' \) -prune -o -type d -print)" ;;
*)
cmd=$kak_opt_fzf_cd_command ;;
items_command=$kak_opt_fzf_cd_command ;;
esac
echo "fzf %{change-directory} %{$cmd}"
}}
tmux_height=$kak_opt_fzf_tmux_height
items_executable=$(printf "%s\n" "$items_command" | grep -o -E "[[:alpha:]]+" | head -1)
if [ -z $(command -v $items_executable) ]; then
printf "%s\n" "fail %{'$items_executable' executable not found}"
exit
fi
tmp=$(mktemp ${TMPDIR:-/tmp}/kak-fzf.XXXXXX)
if [ ! -z "${kak_client_env_TMUX}" ]; then
cmd="$items_command | fzf-tmux -d $tmux_height > $tmp"
elif [ ! -z "${kak_opt_termcmd}" ]; then
fzfcmd=$(mktemp ${TMPDIR:-/tmp}/kak-fzfcmd.XXXXXX)
chmod 755 $fzfcmd
printf "%s\n" "cd $PWD && $items_command | fzf > $tmp" > $fzfcmd
cmd="$kak_opt_termcmd 'sh -c $fzfcmd'"
else
printf "%s\n" "fail termcmd option is not set"
exit
fi
(
eval "$cmd"
if [ -s $tmp ]; then
(
while read item; do
printf "%s\n" "evaluate-commands -client $kak_client 'change-directory' '$item'" | kak -p $kak_session
printf "%s\n" "evaluate-commands -client $kak_client fzf-cd" | kak -p $kak_session
done
) < $tmp
fi
rm $tmp
[ -z "$fzfcmd" ] && rm $fzfcmd
) > /dev/null 2>&1 < /dev/null &
}}