fzf icon indicating copy to clipboard operation
fzf copied to clipboard

Output sorted by length of filename not alpha / numeric

Open Fixles opened this issue 11 years ago • 5 comments

Hello,

I've started using fzf today in vim and added this function to my .bashrc. Which will pass all files as an argument to a command like vlc.

open() { fzf -m -e | xargs -d'\n' -r "$@" ; }

I was hoping to replace a python script I wrote to search and select mp3's from my music collection but the mp3's are sorted by how long the title is not alpha numerically?

Here's a screenshot to better explain what I mean. On the right is a ls directory listing. On the left is fzf run without any arguments in the same directory. When I type "a" the result should be sorted similar to the output of ls.

http://i.imgur.com/lYNADdV.png

This isn't a problem when your selecting a single file but it is when -m is used to open something like a audio book or music album everything is out of order.

Apologies if I've missing something obvious but I couldn't see any way of manipulating the sort order in the documentation beyond not doing any sorting.

Fixles avatar Jun 19 '15 01:06 Fixles

Heres a more practical example. This is a vim course I downloaded from youtube to watch offline. I'd like to select the first couple in the series to pass to vlc but again they are sorted by file length.

http://i.imgur.com/Tk0H8Ki.png

Fixles avatar Jun 19 '15 01:06 Fixles

fzf does not know the meaning of the input. It can be a list of files or processes or any list of things. So as being a general-purpose filter, fzf by default sorts the list

  1. first by the length of the matched substring,
  2. then by the length of the line,
  3. finally by the index number of the line (FIFO)

There are a couple of strategies you can take.

  1. Presort the result and disable sort completely.

    find * -name '*.mp3' | sort | fzf --no-sort
    
  2. Use --tiebreak option to adjust the sorting criteria. See the man page for the details.

    find * -name '*.mp3' | sort | fzf --tiebreak=index
    

junegunn avatar Jun 19 '15 01:06 junegunn

Make sure that you're running the proper go version of fzf. The outdated ruby version does not implement --tiebreak.

junegunn avatar Jun 19 '15 02:06 junegunn

Thanks using sort works perfectly it hadn't occurred to me. Actually I missed there was a go version I just copied the ruby script into my $HOME/bin/

I just grabbed the pre-release version --bind toggle-all is a great new feature!

Fixles avatar Jun 19 '15 10:06 Fixles

0.10.0 is out.

junegunn avatar Jun 21 '15 14:06 junegunn