0

fd searches files and directories, and can be called with except or prune as an option to limit the results.

Is there a way to search only for specified directories? I want to use fd, in fzf, and have the results always computed quickly (so the spinner stops spinning sooner).

2
  • I'm not sure I understand the usecase - do you want to havefd already filter the results, instead of fzf? Do you want to use both to filter the results? fzfs filtering can potentially return more results than fd due to being a fuzzy filter. Do you accept that already filtering in fd would return less results?
    – Wieland
    Feb 28, 2022 at 8:44
  • I've edited the question and also resolved it myself.
    – Pound Hash
    Feb 28, 2022 at 21:07

1 Answer 1

0

Instead of excluding or pruning all the directories except those I want to search through, I used the --search-path option to supply those directories; no need to exclude anything. Here's the configuration (in my zshenv):

# fzf
export CONFIGURATION="--search-path $HOME/.config --search-path $HOME/downloads --search-path $HOME/google_drive --search-path /etc"

export FZF_DEFAULT_COMMAND="fd --type f --hidden --follow $CONFIGURATION . "
export FZF_CTRL_T_COMMAND="$FZF_DEFAULT_COMMAND"
export FZF_ALT_C_COMMAND="fd --type d --hidden --follow $CONFIGURATION . "

_fzf_compgen_path() {
  fd --hidden --follow "$CONFIGURATION" .
}

_fzf_compgen_dir() {
  fd --type d --hidden --follow "$CONFIGURATION" .
}

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.