junegunn / fzf

:cherry_blossom: A command-line fuzzy finder
https://junegunn.github.io/fzf/
MIT License
64.25k stars 2.38k forks source link

make CTRL-T work with directories outside the current one #3860

Closed backpropper closed 3 months ago

backpropper commented 3 months ago

Checklist

Output of fzf --version

0.52.1

OS

Shell

Problem / Steps to reproduce

Let's assume I am in directory /dirA. There is also a /dirB.

Very often there are case where I want to use FZF's CTRL-T to search relative to dirB although I am currently inside dirA.

For example,

cd /dirA ... cd /dirB

(search for /dirA/foo/) How on earth can I achieve that? My CTRL-T is set to toggling with single key as described [here](https://github.com/junegunn/fzf/blob/master/ADVANCED.md#toggling-with-a-single-key-binding). P.S.: I'm able to search for Files outside of dirB here but not directories.
LangLangBart commented 3 months ago

I assume you're relying on fd to list entries in fzf. Did you experiment with the --search-path flag in fd?

print -D $PWD
# ~/Developer/fzf/bin

fd --search-path ../doc --search-path .
./fzf-preview.sh
./fzf-tmux
../doc/fzf.txt

Combined with the reload action, you should be able to accomplish your goal.

fzf --bind 'ctrl-b:reload:fd --search-path ../doc --search-path .'
junegunn commented 3 months ago

I suggest that you use fuzzy completion instead for that purpose.

vim /dirA/**<TAB>

See https://github.com/junegunn/fzf?tab=readme-ov-file#fuzzy-completion-for-bash-and-zsh

Since you're using zsh, also see https://github.com/junegunn/fzf/wiki/Configuring-fuzzy-completion#dedicated-completion-key

backpropper commented 3 months ago

Yes, I've tried the above setting. Your suggestion requires one to exit fzf -> then reopen it with dirA which is my current workflow anyway. I was wondering if it is possible to achieve this without leaving fzf in the first place.