lsd icon indicating copy to clipboard operation
lsd copied to clipboard

Cannot `lsd ~` on windows

Open Nemo157 opened this issue 2 years ago • 8 comments

  • os: Windows 10
  • lsd --version: lsd 1.0.0
  • echo $TERM: PowerShell 7
  • echo $LS_COLORS: -

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.

Nemo157 avatar Sep 15 '23 10:09 Nemo157

sound reasonable!

/kind feature /good-first-issue /help

zwpaper avatar Sep 16 '23 02:09 zwpaper

@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:

sound reasonable!

/kind feature /good-first-issue /help

Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes/test-infra repository.

muniu-bot[bot] avatar Sep 16 '23 02:09 muniu-bot[bot]

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:

  • https://github.com/PowerShell/PowerShell/issues/20031
  • https://github.com/PowerShell/PowerShell/issues/5350
  • https://github.com/PowerShell/PowerShell/pull/12386 (This was a PR that introduced tilde expansion in the PSNativePSPathResolution feature, but it apparently had some edge cases and was later removed)

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

  • cargo build --manifest-path ~\git\lsd\Cargo.toml
  • dotnet build ~/example/example.sln
  • eza ~

domsleee avatar Sep 29 '23 10:09 domsleee

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).

Nemo157 avatar Sep 29 '23 10:09 Nemo157

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

Maybe a vote?

zwpaper avatar Oct 01 '23 09:10 zwpaper

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:

  • fd . ~/
  • bat ~/file

domsleee avatar Oct 02 '23 11:10 domsleee

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

ofersadan85 avatar Jan 02 '24 10:01 ofersadan85