1

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).

Pound Hash
  • 268
  • 4
  • 14
  • I'm not sure I understand the usecase - do you want to have`fd` already filter the results, instead of `fzf`? Do you want to use both to filter the results? `fzf`s 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 '22 at 08:44
  • I've edited the question and also resolved it myself. – Pound Hash Feb 28 '22 at 21:07

1 Answers1

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" .
}
Pound Hash
  • 268
  • 4
  • 14