junegunn / fzf

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

Option to show a different delimiter in the finder than the one used #3478

Closed tobx closed 10 months ago

tobx commented 11 months ago

Info

Problem / Steps to reproduce

I would love to have an option to show a different delimiter in the finder than the one used in the background. This would also solve #2154.

Example:

echo '1:2:;3' | fzf --delimiter '[:;]+' --with-nth '1,3,2'

This displays 1:32:; in the finder.

Introducing a new option like --display-delimiter could solve that problem:

printf '1:2:;3' | fzf --delimiter '[:;]+' --display-delimiter ' : ' --with-nth '1,3,2'

This could easily display 1 : 3 : 2, because https://github.com/junegunn/fzf/issues/2154#issuecomment-682589184 would not be a problem in this case.

This would also enable users to use a "safe" delimiter like NUL and display a human readable delimiter in the finder.

junegunn commented 10 months ago

I would recommend using an external tool to pre-process the input.

printf '1:2:;3' |
  awk -F'[:;]+' 'BEGIN {OFS=" : "} {print $0 "\t" $1, $3, $2}' |
  fzf --delimiter "\t" --with-nth 2.. |
  awk -F"\t" '{print $1}'

This approach is much more flexible than the suggested option. You can use any tool you want to format the text any way you want.

tobx commented 10 months ago

@junegunn This does not work if you also want to use --nth. And with --display-delimiter it would be possible to make fzf not match the delimiter itself in a search.