lotabout / skim

Fuzzy Finder in rust!
MIT License
5.07k stars 180 forks source link

Field expressions handle leading spaces differently than `fzf` #457

Open cpick opened 2 years ago

cpick commented 2 years ago

Field expressions were changed in https://github.com/lotabout/skim/pull/85 from "git style" to attempt to match fzf's behavior, but they exhibit different behavior when there are leading spaces.

For example, running the following with fzf (note leading space in input):

echo ' first second' | fzf -n2.. --preview 'echo {2..}'

Prints only the "second" column in the preview pane:

>  first second | second

Whereas, running with sk (including leading space in input):

echo ' first second' | sk -n2.. --preview 'echo {2..}'

Prints both columns in the preview pane:

>  first second | first second

This actually breaks using skim as a fzf replacement with zoxide. It calls fzf/sk with similar -n2.. and --preview 'ls {2..}' arguments (among others) and then provides lines of input that start with a leading-space-padded 4-digit score followed by directory names like this:

2064 /Users/cpick/src
 108 /Users/cpick/src/foo
  44 /Users/cpick
  40 /Users/cpick/bar/baz

And the difference in field expressions cause selection to happen on less-than-4-digit leading scores and also the preview command to break because it gets passed the same less-than-4-digit scores in addition to the filename.

cpick commented 2 years ago

It looks like this is because fzf does awk-like tokenization by default (unless a delimiter is provided). I think changing the various default DELIMITER_STRs from [\t\n ]+ to [^\t\n ][\t\n ]+ will more or less fix it (the first field will still have the leading white space included which is different than fzf, but it's good enough for my purposes).