vors / ZLocation

ZLocation is the new Jump-Location
MIT License
564 stars 29 forks source link

:bug: the second weighted path is picked #76

Open zhaocai opened 5 years ago

zhaocai commented 5 years ago

:bug: Somehow, the second weighted path is picked.

> z -l posh

Weight Path
------ ----
   107 C:\Users\Zhao\Documents\WindowsPowerShell\Modules\oh-my-posh
    65 C:\Users\Zhao\Documents\WindowsPowerShell\Modules\posh-git
    12 C:\Users\Zhao\Documents\WindowsPowerShell\Modules\git-status-cache-posh-client
     6 C:\ProgramData\chocolatey\lib\git-status-cache-posh-client
     6 C:\ProgramData\chocolatey\lib\git-status-cache-posh-client\tools\git-status-cache-posh-client-1.0.0

> z posh ; pwd

Path
----
C:\Users\Zhao\Documents\WindowsPowerShell\Modules\posh-git

👍 However, sometimes the first weighted path is chosen as expected.

> z -l app

Weight Path
------ ----
    16 C:\tools\scoop\apps
    12 C:\Users\Zhao\AppData
     7 C:\Users\Zhao\AppData\Local\atom\app-1.9.9
     5 C:\Users\Zhao\Dropbox\Apps

 z app ; pwd

Path
----
C:\tools\scoop\apps

💡 Any idea?

vors commented 5 years ago

Hmm, I think there could be some logic about preferring the (apparently case-sensitive) prefixes... cannot quickly find it.

Snaptags commented 5 years ago

I have similar cases and my guess is that matches at the beginning of the folder name are being preferred, regardless of the entry's weight: 107 C:\Users\Zhao\Documents\WindowsPowerShell\Modules\oh-my-posh 65 C:\Users\Zhao\Documents\WindowsPowerShell\Modules\posh-git

That is of course a valid metric, BUT weight should overrule the "beginning of name" rule.

theaquamarine commented 5 years ago

The issue is at https://github.com/vors/ZLocation/blob/29cb9e6cf90a331c2f823e94772e1a027d464425/ZLocation/ZLocation.Search.psm1#L18-L30, the results are sorted by whether or not they start with the prefix, then by their value. Changing https://github.com/vors/ZLocation/blob/29cb9e6cf90a331c2f823e94772e1a027d464425/ZLocation/ZLocation.Search.psm1#L30 to Sort-Object -Property Value, Starts -Descending should resolve this, as results will then be sorted by value first, only using the prefix if two have the same value.

vors commented 5 years ago

Oh yeah, I remember now. #26 where it started. I don't know what's really the right answer here - should the tool try to be smarter or should it try to be dumber but more predictable.

eamodio commented 1 year ago

I have been seeing the same issue and its been driving me nuts 😄

deviousasti commented 1 year ago

Any workarounds for this?