From 18dfd2458dc741fea683357a17aaa95870b25a3c Mon Sep 17 00:00:00 2001 From: Luis Calle <53507599+TheLeoP@users.noreply.github.com> Date: Mon, 4 Mar 2024 13:50:22 -0500 Subject: [PATCH] fix(windows): can delete non-ascii filenames to trash (#323) --- .../trash/windows/powershell-connection.lua | 13 +++++-------- lua/oil/adapters/trash/windows/powershell-trash.lua | 2 -- 2 files changed, 5 insertions(+), 10 deletions(-) diff --git a/lua/oil/adapters/trash/windows/powershell-connection.lua b/lua/oil/adapters/trash/windows/powershell-connection.lua index aeb426f..f16c346 100644 --- a/lua/oil/adapters/trash/windows/powershell-connection.lua +++ b/lua/oil/adapters/trash/windows/powershell-connection.lua @@ -27,15 +27,12 @@ end ---@param init_command? string function PowershellConnection:_init(init_command) + -- 65001 is the UTF-8 codepage + -- powershell needs to be launched with the UTF-8 codepage to use it for both stdin and stdout local jid = vim.fn.jobstart({ - "powershell", - "-NoProfile", - "-NoLogo", - "-ExecutionPolicy", - "Bypass", - "-NoExit", - "-Command", - "-", + "cmd", + "/c", + '"chcp 65001 && powershell -NoProfile -NoLogo -ExecutionPolicy Bypass -NoExit -Command -"', }, { ---@param data string[] on_stdout = function(_, data) diff --git a/lua/oil/adapters/trash/windows/powershell-trash.lua b/lua/oil/adapters/trash/windows/powershell-trash.lua index 87a7465..a176493 100644 --- a/lua/oil/adapters/trash/windows/powershell-trash.lua +++ b/lua/oil/adapters/trash/windows/powershell-trash.lua @@ -10,10 +10,8 @@ local Powershell = require("oil.adapters.trash.windows.powershell-connection") local M = {} --- The first line configures Windows Powershell to use UTF-8 for input and output -- 0xa is the constant for Recycle Bin. See https://learn.microsoft.com/en-us/windows/win32/api/shldisp/ne-shldisp-shellspecialfolderconstants local list_entries_init = [[ -$OutputEncoding = [Console]::InputEncoding = [Console]::OutputEncoding = New-Object System.Text.UTF8Encoding $shell = New-Object -ComObject 'Shell.Application' $folder = $shell.NameSpace(0xa) ]]