lsd-rs / lsd

The next gen ls command
Apache License 2.0
13.16k stars 429 forks source link

Cannot `lsd ~` on windows #903

Open Nemo157 opened 12 months ago

Nemo157 commented 12 months ago

Expected behavior

The same as ls $env:HOME

Actual behavior

lsd: ~: The system cannot find the file specified. (os error 2).

Notes

It appears that lsd supports globs itself on windows, I would expect it to do the same for other common shell shorthands like ~ that powershell doesn't expand itself.

zwpaper commented 12 months ago

sound reasonable!

/kind feature /good-first-issue /help

muniu-bot[bot] commented 12 months ago

@zwpaper: This request has been marked as suitable for new contributors.

Please ensure the request meets the requirements listed here.

If this request no longer meets these requirements, the label can be removed by commenting with the /remove-good-first-issue command.

In response to [this](https://github.com/lsd-rs/lsd/issues/903): >sound reasonable! > >/kind feature >/good-first-issue >/help > Instructions for interacting with me using PR comments are available [here](https://git.k8s.io/community/contributors/guide/pull-requests.md). If you have questions or suggestions related to my behavior, please file an issue against the [kubernetes/test-infra](https://github.com/kubernetes/test-infra/issues/new?title=Prow%20issue:) repository.
domsleee commented 11 months ago

Although I agree lsd ~ should work in powershell, I think it is a shell feature and should be tackled in the powershell repo

It looks like there are two funny behaviours in pwsh (7.3.7, on windows):

  1. Tilde is not expanded for native programs (only some cmdlets, e.g. Get-ChildItem ~)
  2. Pressing <tab> will expand tilde, if there is a completion

Notably, tilde expansion works correctly on mac with pwsh 7.3.7 (case 1 here).

Related:

Other programs that don't do tilde expansion for pwsh:

Nemo157 commented 11 months ago

Tilde is not expanded for native programs (only some cmdlets, e.g. Get-ChildItem ~)

AFAIK tilde is not expanded for anything, Get-ChildItem receives a path with a tilde in it and internally expands it, the same as any other application that supports tilde paths on windows. (Which is why both gci ~ and gci '~' work the same, there's no shell expansion for the quotes to suppress).

zwpaper commented 11 months ago

then we may need more information to decide whether this should be implemented

Maybe a vote?

domsleee commented 11 months ago

Which is why both gci ~ and gci '~' work the same, there's no shell expansion for the quotes to suppress

Oh yeah you're right, the cmdlets replace the tilde regardless of quotes, so it isn't really an expansion 👍

Other cmdlets like Get-Content also have this "tilde replacement" behaviour.

I opened a PR with powershell: https://github.com/PowerShell/PowerShell/pull/20402

We could consider using the same logic as starship here, which uses dirs-next: https://github.com/starship/starship/blob/7e82cb494c540c7a88cf126ec80aeb0f7ce611bc/src/context.rs#L212C1-L218C6

Do you know any programs that implement tilde replacement? It seems uncommon, a few more examples that don't have it:

ofersadan85 commented 8 months ago

I'm preparing a PR for this support. Worth noting that this expansion is supported when looking for theme files