aperezdc / zsh-fzy

Use the fzy fuzzy-finder in Zsh
MIT License
55 stars 9 forks source link

Make commands configurable #9

Closed maximbaz closed 5 years ago

maximbaz commented 5 years ago

I'd like to replace find command used in fzy-file-widget with something else, for example rg --files. Same would apply for fzy-cd-widget.

This would allow me to ignore certain files and folders, for example I never want to look for files inside .git directory.

aperezdc commented 5 years ago

This is a good idea, I think adding a couple of options settable with zstyle will be the way to go, e.g.:

zstyle :fzy:file command <string>
zstyle :fzy:cd   command <string>

where <string> can be any command that produces a list of elements on standard output, one per line. In particular I think it is important to allow using shell functions, to allow any complex behavior. Silly example:

function list-files-for-fzy {
    rg --files | rg -vF '/old/'
} 

zstyle :fzy:file command list-files-for-fzy

On top of allowing for more customization, this would also allow to wrap the commands currently being used inside functions to easily reuse them as defaults.

maximbaz commented 5 years ago

This is powerful, just to confirm, would it always be necessary to define a function, or something like this would work too?

zstyle :fzy:file command 'rg --files'
aperezdc commented 5 years ago

@maximbaz Defining a function will be optional. Your configuration using the command string directly should work as well.

aperezdc commented 5 years ago

@maximbaz The needed changes are now in master, please update, and let me know if you find any problem with the new feature. Note that the zstyle settings for command are arrays, and you will need to use the following:

zstyle :fzy:file command rg --files  # No quoting needed.
maximbaz commented 5 years ago

Works very well, thanks a lot!