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

🐛 the second weighted path is picked #76

Open
zhaocai opened this issue Dec 28, 2018 · 6 comments
Open

🐛 the second weighted path is picked #76

zhaocai opened this issue Dec 28, 2018 · 6 comments

Comments

@zhaocai
Copy link

zhaocai commented Dec 28, 2018

🐛 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?

@zhaocai zhaocai changed the title 🐛 the second weighted path is picked :bug the second weighted path is picked Dec 28, 2018
@zhaocai zhaocai changed the title :bug the second weighted path is picked 🐛 the second weighted path is picked Dec 28, 2018
@vors
Copy link
Owner

vors commented Dec 28, 2018

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

@Snaptags
Copy link

Snaptags commented Apr 10, 2019

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
Copy link
Collaborator

The issue is at

# we should prefer paths that start with the query over paths with bigger weight
# that don't.
# i.e. if we have
# /foo = 1.0
# /afoo = 2.0
# and query is "fo", we should prefer /foo
$res = $hash.GetEnumerator() | % {
New-Object -TypeName PSCustomObject -Property @{
Name=$_.Name
Value=$_.Value
Starts=[int](Start-WithPrefix -Path $_.Name -lowerPrefix $lowerPrefix)
}
} | Sort-Object -Property Starts, Value -Descending
, the results are sorted by whether or not they start with the prefix, then by their value. Changing
} | Sort-Object -Property Starts, Value -Descending
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.

theaquamarine added a commit to theaquamarine/ZLocation that referenced this issue Apr 14, 2019
Prefix then weight system lead to surprising behaviour eg vors#76
@vors
Copy link
Owner

vors commented Apr 21, 2019

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
Copy link

eamodio commented Oct 21, 2022

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

@deviousasti
Copy link

Any workarounds for this?

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

No branches or pull requests

6 participants