2018-11-11 10:41:15 +00:00
|
|
|
# ╭─────────────╥────────────────────────╮
|
|
|
|
# │ Author: ║ File: │
|
|
|
|
# │ Andrey Orst ║ fzf-cd.kak │
|
|
|
|
# ╞═════════════╩════════════════════════╡
|
|
|
|
# │ Module for changing directories with │
|
|
|
|
# │ fzf for fzf.kak plugin │
|
|
|
|
# ╞══════════════════════════════════════╡
|
|
|
|
# │ GitHub.com/andreyorst/fzf.kak │
|
|
|
|
# ╰──────────────────────────────────────╯
|
|
|
|
|
|
|
|
declare-option -docstring "command to provide list of directories to fzf.
|
|
|
|
Default value:
|
|
|
|
find: (echo .. && find \( -path '*/.svn*' -o -path '*/.git*' \) -prune -o -type d -print)
|
|
|
|
" \
|
|
|
|
str fzf_cd_command "find"
|
|
|
|
|
|
|
|
map global fzf -docstring "change directory" 'c' '<esc>: fzf-cd<ret>'
|
|
|
|
|
|
|
|
define-command -hidden fzf-cd %{ evaluate-commands %sh{
|
2018-11-24 11:39:54 +00:00
|
|
|
tmux_height=$kak_opt_fzf_tmux_height
|
2018-11-22 12:36:32 +00:00
|
|
|
printf '%s\n' "info -title %{fzf change directory} %{Change the server's working directory}"
|
|
|
|
|
|
|
|
case $kak_opt_fzf_cd_command in
|
2018-11-11 10:41:15 +00:00
|
|
|
find)
|
2018-11-22 12:36:32 +00:00
|
|
|
items_command="(echo .. && find \( -path '*/.svn*' -o -path '*/.git*' \) -prune -o -type d -print)" ;;
|
2018-11-11 10:41:15 +00:00
|
|
|
*)
|
2018-11-22 12:36:32 +00:00
|
|
|
items_command=$kak_opt_fzf_cd_command ;;
|
|
|
|
esac
|
|
|
|
|
2018-11-24 11:39:54 +00:00
|
|
|
tmp=$(mktemp ${TMPDIR:-/tmp}/kak-fzf-tmp.XXXXXX)
|
|
|
|
fzfcmd=$(mktemp ${TMPDIR:-/tmp}/kak-fzfcmd.XXXXXX)
|
|
|
|
printf "%s\n" "cd $PWD && $items_command | SHELL=$(command -v sh) fzf > $tmp" > $fzfcmd
|
|
|
|
chmod 755 $fzfcmd
|
2018-11-22 12:36:32 +00:00
|
|
|
|
2018-11-24 11:39:54 +00:00
|
|
|
if [ -n "$kak_client_env_TMUX" ]; then
|
|
|
|
[ -n "${tmux_height%%*%}" ] && measure="-p" || measure="-p"
|
|
|
|
cmd="command tmux split-window $measure ${tmux_height%%%*} 'sh -c $fzfcmd; rm $fzfcmd'"
|
|
|
|
elif [ -n "$kak_opt_termcmd" ]; then
|
|
|
|
cmd="$kak_opt_termcmd 'sh -c $fzfcmd; rm $fzfcmd'"
|
2018-11-22 12:36:32 +00:00
|
|
|
else
|
2018-11-24 11:39:54 +00:00
|
|
|
printf "%s\n" "fail %{termcmd option is not set}"
|
|
|
|
rm $fzfcmd
|
|
|
|
rm $tmp
|
2018-11-22 12:36:32 +00:00
|
|
|
exit
|
|
|
|
fi
|
|
|
|
|
|
|
|
(
|
|
|
|
eval "$cmd"
|
2018-11-24 11:39:54 +00:00
|
|
|
while [ -e $fzfcmd ]; do
|
|
|
|
sleep 0.1
|
|
|
|
done
|
2018-11-22 12:36:32 +00:00
|
|
|
if [ -s $tmp ]; then
|
|
|
|
(
|
|
|
|
while read item; do
|
2018-11-24 11:39:54 +00:00
|
|
|
printf "%s\n" "evaluate-commands -client $kak_client change-directory %{$item}" | kak -p $kak_session
|
2018-11-22 12:36:32 +00:00
|
|
|
printf "%s\n" "evaluate-commands -client $kak_client fzf-cd" | kak -p $kak_session
|
|
|
|
done
|
|
|
|
) < $tmp
|
|
|
|
fi
|
|
|
|
rm $tmp
|
|
|
|
) > /dev/null 2>&1 < /dev/null &
|
|
|
|
}}
|
2018-11-24 11:39:54 +00:00
|
|
|
|