0

I just discovered fzf (fuzzy finder) and now want to achieve the following using fd (https://github.com/sharkdp/fd): From the current directory find immediate parent directories of all files that match the string I typed as well as find directories whose name match the string I typed.

I tried doing cd "$(fd | fzf)" but the problem which occurs here is that for matching files fd | fzf will obviously output the full path to the file and not just to the parent directory meaning cd fails on this output. Is there a way of rectifying this without having to define separate commands for each of the above listed conditions?

2
  • I'm not exactly sure what you want, but would something like T="$(fd | fzf)" ; if [[ -f "$T" ]] ; then T="$(dirname "$T")" ; fi ; cd "$T" suffice? I.e., if you pick a directory, cd into it; if you pick a file, cd into its directory?
    – frabjous
    Commented Aug 28, 2022 at 22:54
  • @frabjous thanks a lot!
    – Richard
    Commented Aug 29, 2022 at 9:42

1 Answer 1

0

has no option to report only the dirnames of the located files.

You might want to approach the fzf developers to discuss whether such an option would fall within the scope of their vision for its functionality. As for dirname, it performs the limited functionality it does in line with Unix's early tradition for many narrowly-focused and independant utilities.

At this time, an approach such as that proposed by frapjous is your only alternative.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .