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

PowerShell snippet to run onefetch on directory change can break tools that wrap Set-Location (cd) #1467

Open
spenserblack opened this issue Nov 12, 2024 · 1 comment

Comments

@spenserblack
Copy link
Collaborator

spenserblack commented Nov 12, 2024

zoixde yazi can not use ,Unable to jump

Originally posted by @Wu-Felix in #1452 (comment)

@spenserblack
Copy link
Collaborator Author

spenserblack commented Nov 12, 2024

I think I know what the problem is for Yazi (and likely zoxide, too). Yazi has this recommended wrapper for PowerShell to CD into the last directory used:

function y {
    $tmp = [System.IO.Path]::GetTempFileName()
    yazi $args --cwd-file="$tmp"
    $cwd = Get-Content -Path $tmp
    if (-not [String]::IsNullOrEmpty($cwd) -and $cwd -ne $PWD.Path) {
        Set-Location -LiteralPath $cwd
    }
    Remove-Item -Path $tmp
}

I don't know much PowerShell, but I'm guessing that @Wu-Felix's issue is caused because the custom Set-Location takes -Path, but the Yazi wrapper uses -LiteralPath. So the y wrapper fails to CD ("jump").

Perhaps this can be easily fixed by accepting and passing any parameter from the custom Set-Location to the builtin Set-Location for better compatibility? Here's a simple example of what I mean:

function Set-Location-Proxy {
    # do something
    Set-Location @args
}

cc @kiapanahi

I'd happily accept a PR from either of you 🙂

@spenserblack spenserblack changed the title PowerShell snippet can break tools that wrap Set-Location (cd) PowerShell snippet to run onefetch on directory change can break tools that wrap Set-Location (cd) Nov 12, 2024
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

1 participant