yazi-rs / yazi-rs.github.io

Documentation site for Yazi.
https://yazi-rs.github.io
MIT License
25 stars 90 forks source link

Powershell "y" alias decoding error. #170

Open sxyazi opened 5 days ago

sxyazi commented 5 days ago

Originally posted by @Aqaao in https://github.com/sxyazi/yazi/issues/1921


What system are you running Yazi on?

Windows

What terminal are you running Yazi in?

wezterm

yazi --debug output

None

Describe the bug

Windows powershell Chinese character decoding error when use "y" command.

Minimal reproducer

start yazi via "y" alias, select a path that contains Chinese characters, then press "q" quit yazi. 图片 图片

Anything else?

Resolved via add -Encoding UTF8 arg to Powershell wrapper function's line 4.

$cwd = Get-Content -Path $tmp  -Encoding UTF8 

Maybe docs should be modified to add this arg ?

Validations

luiz00martins commented 4 days ago

Hey, @sxyazi! The -Encoding UTF8 solution works fine for me.

This is the final one I'd use:

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

Also added GetFullPath, to convert possible / to \, if it ever comes to that.

sxyazi commented 4 days ago

Nice! Would you like to raise a PR to get the credit?