1
0
Fork 0

Feature to allow users to open a file in the same directory as the current file

Let say you have a file open in a kakoune buffer and you are currently interested
in opening another file _only_ in the _same_ directory as the current file.
You could do this with the usual `<fzf-mode> f` but that will
list many files you are not interested in.

Add functionality and shortcut `<fzf-mode> F` that will list the files
only in the directory of the currently displayed file. This is useful
when your kakoune current directory is different from the directory
of the currently displayed file.

E.g. if you have /home/abc/xzy/lmn/hello.cpp open in kakoune and your current
directory in kakoune is /home/abc/xyz then `<fzf-mode> F` will list all files in
/home/abc/xyz/lmn as candidates for opening.
This commit is contained in:
Sidharth Kshatriya 2022-01-16 00:28:32 +05:30 committed by Andrey Listopadov
parent d98b16680c
commit e91b76c517

View file

@ -4,6 +4,7 @@
hook global ModuleLoaded fzf %{ hook global ModuleLoaded fzf %{
map global fzf -docstring "open file" 'f' '<esc>: require-module fzf-file; fzf-file<ret>' map global fzf -docstring "open file" 'f' '<esc>: require-module fzf-file; fzf-file<ret>'
map global fzf -docstring "open file in dir of currently displayed file" 'F' '<esc>: require-module fzf-file; fzf-file buffile-dir<ret>'
} }
provide-module fzf-file %§ provide-module fzf-file %§
@ -31,7 +32,15 @@ Default value:
bool fzf_file_preview true bool fzf_file_preview true
define-command -hidden fzf-file %{ evaluate-commands %sh{ define-command -hidden fzf-file -params 0..1 %{ evaluate-commands %sh{
search_dir="."
if [ "$1" = "buffile-dir" ]; then
# dirname will return '.' if the file is non-existent.
# This value is a fail-safe default if we ever use buffile-dir functionality
# by mistake on files that do not have a directory e.g. *scratch*
search_dir=$(dirname "$kak_buffile")
fi
if [ -z "$(command -v "${kak_opt_fzf_file_command%% *}")" ]; then if [ -z "$(command -v "${kak_opt_fzf_file_command%% *}")" ]; then
printf "%s\n" "echo -markup '{Information}''$kak_opt_fzf_file_command'' is not installed. Falling back to ''find'''" printf "%s\n" "echo -markup '{Information}''$kak_opt_fzf_file_command'' is not installed. Falling back to ''find'''"
kak_opt_fzf_file_command="find" kak_opt_fzf_file_command="find"
@ -47,7 +56,7 @@ define-command -hidden fzf-file %{ evaluate-commands %sh{
cmd=$kak_opt_fzf_file_command ;; cmd=$kak_opt_fzf_file_command ;;
esac esac
cmd="$cmd 2>/dev/null" cmd="cd $search_dir; $cmd 2>/dev/null"
message="Open single or multiple files. message="Open single or multiple files.
<ret>: open file in new buffer. <ret>: open file in new buffer.
${kak_opt_fzf_window_map:-ctrl-w}: open file in new terminal" ${kak_opt_fzf_window_map:-ctrl-w}: open file in new terminal"