Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Items appear in reverse alphabetical order #21

Closed
gene-pavlovsky opened this issue Nov 19, 2019 · 7 comments · Fixed by #31
Closed

Items appear in reverse alphabetical order #21

gene-pavlovsky opened this issue Nov 19, 2019 · 7 comments · Fixed by #31

Comments

@gene-pavlovsky
Copy link

OS: macOS 10.15.1

Something is wrong with the sort order of the results displayed by fzf-obc.

Without fzf-obc, ls /[TAB][TAB]:

.DS_Store         .vol/             System/           cores/            opt/              usr/              
.VolumeIcon.icns  Applications/     Users/            dev/              private/          var/              
.file             Library/          Volumes/          etc/              sbin/             
.fseventsd/       Network/          bin/              home/             tmp/              

With fzf-obc enabled:

$ ls /
>                                                                                                                              
  22/22                                                                                                                        
> Volumes/                                                                                                                     
  var/                                                                                                                         
  usr/                                                                                                                         
  Users/                                                                                                                       
  tmp/                                                                                                                         
  System/                                                                                                                      
  sbin/                                                                                                                        
  private/                                                                                                                     
  opt/                                                                                                                         
  Network/                                                                                                                     
  Library/                                                                                                                     
  home/                                                                                                                        
  etc/

Note that the order of the result is reverse alphabetic, and case seems to be ignored.
Original sort order is alphabetic, with all uppercase letters before all lowercase ones.

@rockandska
Copy link
Owner

This behavior was clearly a personal choice (but could be change by the user).

The main reason is :

  • having hidden files displayed first is generally not what we want. We generally not lookup at first at hidden files/directories.
  • having fzf over bash completion is to use its fuzzy search capabilities and is not intend to have a nice display but more having an easy way to search for something since we generally know what we looking for
  • found weird to be case sensitive and more logical to be not ^^

Having multiple columns to display the results will be better but fzf is not open to use the full width to display multi columns.

Anyway, it is not well documented yet and have a lack in CI tests, but you could override the default sort function, have a sort function by command, or have a sort function by completion function.

So, if you would like to have for all commands sort without be case sensitive, and in the "normal" order, you could override the default function by the one bellow.
You could also put this definition in a dedicated directory if you would like and having it loaded by fzf-obc if you set FZF_OBC_PATH just before sourcing fzf-obc in your .bashrc:

$ mkdir -p > ~/.config/fzf-obc
$ cat > ~/.config/fzf-obc/sort.sh
__fzf_obc_default_sort () { 
    local cmd;
    cmd="sed -z -r 's/^(\x1B\[([0-9]{1,}(;[0-9]{1,})?(;[0-9]{1,})?)?[mGK])(.*)/\5\1/g'";
    cmd="(set -euo pipefail; eval LC_ALL=C sort -z -u $* -S 50% --parallel=\"$(awk '/^processor/{print $3}' /proc/cpuinfo 2> /dev/null | wc -l)\" 2> /dev/null || eval LC_ALL=C sort -z -u $*) < <($cmd)";
    cmd="sed -z -r 's/(.*)(\x1B\[([0-9]{1,}(;[0-9]{1,})?(;[0-9]{1,})?)?[mGK])$/\2\1/g' < <($cmd)";
    eval "$cmd"
}

If for some reason you would like to change the sort function only for ls for example, it could be achieve like this :

__fzf_obc_sort_ls() {
    local cmd;
    cmd="sed -z -r 's/^(\x1B\[([0-9]{1,}(;[0-9]{1,})?(;[0-9]{1,})?)?[mGK])(.*)/\5\1/g'";
    cmd="(set -euo pipefail; eval LC_ALL=C sort -z -u $* -S 50% --parallel=\"$(awk '/^processor/{print $3}' /proc/cpuinfo 2> /dev/null | wc -l)\" 2> /dev/null || eval LC_ALL=C sort -z -u $*) < <($cmd)";
    cmd="sed -z -r 's/(.*)(\x1B\[([0-9]{1,}(;[0-9]{1,})?(;[0-9]{1,})?)?[mGK])$/\2\1/g' < <($cmd)";
    eval "$cmd"
}

Hope it will help you.
Feel free to close this issue if it fill your needs

rockandska added a commit that referenced this issue Dec 11, 2019
@rockandska
Copy link
Owner

With the new configuration in place, all you have to do to change the sort order now is to use something as below

For example, if you'd like to have hidden files first (default at the end), and the sort not to be case sensitive :

$ cat > ${XDG_CONFIG_HOME:-$HOME/.config}/fzf-obc/default.cfg
std_sort_opts=''      
std_filedir_hidden_first='1'

@gene-pavlovsky
Copy link
Author

I was trying out the default.cfg with std_sort_opts set to either '' or '-Vd'.
However in both cases I didn't notice any changes, and the results are still case-insensitive.
The hidden first option also didn't cause any effect.
I've done "git pull" in fzf-obc's dir, branch is master.
I've placed default.cfg in ~/.local/opt/fzf-obc/default.cfg
What am I doing wrong?

@rockandska
Copy link
Owner

Hi,

All configuration should reside in ~/.config/fzf-obc/ as stated in #21 (comment) and in the doc

For the case-sensitive behavior (this issue was for reverse order), add the sort '-f' option and you will be good.

$ cat > ${XDG_CONFIG_HOME:-$HOME/.config}/fzf-obc/default.cfg
std_sort_opts='-f'      
std_filedir_hidden_first='1'

Regards

@gene-pavlovsky
Copy link
Author

Thanks. I didn't pay enough attention to the proper location of the config file.
I don't get it why did you suggest to set std_sort_opts to -f for case-sensitive behavior. The -f option is for case-insensitive sort, opposite of what I want? I've tried with -V and -Vd and indeed the sort becomes case-sensitive. A-Z are shown before a-z, which is what I want indeed.
I don't really prefer having the dotfiles first, I'd like them to be last, actually. Setting std_filedir_hidden_first to 0 seems to accomplish this, with one issue - they don't seem to be sorted at all! Should I file a separate issue for this?

@rockandska
Copy link
Owner

I don't get it why did you suggest to set std_sort_opts to -f for case-sensitive behavior.

Was just a little tired ^^

they don't seem to be sorted at all!

Hummm weird.

Should I file a separate issue for this?

Yep, one problem -> one issue and don't forget to provide a reproducible case or eventually a screenshot please :)

And thanks for your time :)

@gene-pavlovsky
Copy link
Author

Right, I thought so.
#37
Thanks to you. I'm always happy to file issues wherever I find them.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants