junegunn / fzf

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

Transform presentation of input by cutting out regex patterns #2610

Closed BanchouBoo closed 3 years ago

BanchouBoo commented 3 years ago

Info

Similar to with-nth, but instead of delimiting the input and selecting a field, you just pass in a regex pattern to cut out of the input lines without effecting the final selected output.

As an example, I use fzf to select video files to open with mpv, and I have files with names like [SubsPlease] Fumetsu no Anata e - 01 (1080p) [1D65E30D].mkv, all the extra information isn't exactly condusive to searching and it's not nice to look at either, and while this one example could be handled with a delimiter, not every file would have the same exact field for with-nth so it isn't an effective option. Instead, if I could do something like fzf --cut '(\[\w+\])|(\(\w+\))|\.\w+$' to transform the line to Fumetsu no Anata e - 01 that would be much nicer and more widely applicable.

vovcacik commented 3 years ago

Interesting idea

junegunn commented 3 years ago

fzf was designed with Unix philosophy in mind, it doesn't try to do things that other programs can do better.

In this case, you can 1. preprocess the input string using any program of your choice, 2. feed the original input along with its modified representation to fzf, 3. hide the original using --with-nth, 4. and extract the original input string with another filter program. This approach is much more flexible than fzf implementing a certain string transformation mechanism.

find */* | awk '{print $0 "\t" gensub("/", "🌈 ", "g")}' | fzf --delimiter "\t" --with-nth 2.. | awk -F"\t" '{print $1}'