Output sorted by length of filename not alpha / numeric
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.
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
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
- first by the length of the matched substring,
- then by the length of the line,
- finally by the index number of the line (FIFO)
There are a couple of strategies you can take.
-
Presort the result and disable sort completely.
find * -name '*.mp3' | sort | fzf --no-sort -
Use
--tiebreakoption to adjust the sorting criteria. See the man page for the details.find * -name '*.mp3' | sort | fzf --tiebreak=index
Make sure that you're running the proper go version of fzf. The outdated ruby version does not implement --tiebreak.
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!
0.10.0 is out.