Fix the open files in directory of current file feature
Since we cd-ed into search dir in $cmd, prefix the $search_dir path after fzf returns the results by using -filter switch of fzf. Kakoune either needs an absolute path or path relative to its pwd to edit a file. Since the pwd of $cmd and kakoune now differ, we cannot use a relative path, so we construct the absolute path by prefixing the $search_dir to the file outputted by fzf.
This commit is contained in:
parent
16e001c3a2
commit
010e395041
1 changed files with 8 additions and 1 deletions
|
@ -59,6 +59,13 @@ define-command -hidden fzf-file -params 0..1 %{ evaluate-commands %sh{
|
|||
esac
|
||||
|
||||
cmd="cd $search_dir; $cmd 2>/dev/null"
|
||||
maybe_filter_param=""
|
||||
if [ "$search_dir" != "." ]; then
|
||||
# Since we cd-ed into search dir in $cmd, prefix the $search_dir path after fzf returns the results by using -filter switch of fzf.
|
||||
# Kakoune either needs an absolute path or path relative to its pwd to edit a file. Since the pwd of $cmd and kakoune now differ,
|
||||
# we cannot use a relative path, so we construct the absolute path by prefixing the $search_dir to the file outputted by fzf.
|
||||
maybe_filter_param=$(printf "%s %s" "-filter" "%{perl -pe \"if (/${kak_opt_fzf_window_map:-ctrl-w}|${kak_opt_fzf_vertical_map:-ctrl-v}|${kak_opt_fzf_horizontal_map:-ctrl-s}|^$/) {} else {print \\\"$search_dir/\\\"\"}}")
|
||||
fi
|
||||
message="Open single or multiple files.
|
||||
<ret>: open file in new buffer.
|
||||
${kak_opt_fzf_window_map:-ctrl-w}: open file in new terminal"
|
||||
|
@ -69,7 +76,7 @@ ${kak_opt_fzf_vertical_map:-ctrl-v}: open file in vertical split"
|
|||
printf "%s\n" "info -title 'fzf file' '$message$tmux_keybindings'"
|
||||
[ -n "${kak_client_env_TMUX}" ] && additional_flags="--expect ${kak_opt_fzf_vertical_map:-ctrl-v} --expect ${kak_opt_fzf_horizontal_map:-ctrl-s}"
|
||||
[ "${kak_opt_fzf_file_preview:-}" = "true" ] && preview_flag="-preview"
|
||||
printf "%s\n" "fzf $preview_flag -kak-cmd %{edit -existing} -items-cmd %{$cmd} -fzf-args %{-m --expect ${kak_opt_fzf_window_map:-ctrl-w} $additional_flags}"
|
||||
printf "%s\n" "fzf $preview_flag $maybe_filter_param -kak-cmd %{edit -existing} -items-cmd %{$cmd} -fzf-args %{-m --expect ${kak_opt_fzf_window_map:-ctrl-w} $additional_flags}"
|
||||
}}
|
||||
|
||||
§
|
||||
|
|
Loading…
Reference in a new issue