From 96f0983e754694e592d4313f583cd31eaebfa80d Mon Sep 17 00:00:00 2001 From: Steven Arcangeli Date: Tue, 23 Apr 2024 20:20:58 -0700 Subject: [PATCH] fix(windows): file operation preview uses only backslash path separator (#336) --- lua/oil/adapters/files.lua | 2 +- lua/oil/util.lua | 12 +++++++++--- 2 files changed, 10 insertions(+), 4 deletions(-) diff --git a/lua/oil/adapters/files.lua b/lua/oil/adapters/files.lua index 89eb810..cf6f73e 100644 --- a/lua/oil/adapters/files.lua +++ b/lua/oil/adapters/files.lua @@ -40,7 +40,7 @@ end M.to_short_os_path = function(path, entry_type) local shortpath = fs.shorten_path(fs.posix_to_os_path(path)) if entry_type == "directory" then - shortpath = util.addslash(shortpath) + shortpath = util.addslash(shortpath, true) end return shortpath end diff --git a/lua/oil/util.lua b/lua/oil/util.lua index bd2f048..a685b14 100644 --- a/lua/oil/util.lua +++ b/lua/oil/util.lua @@ -337,10 +337,16 @@ M.set_highlights = function(bufnr, highlights) end ---@param path string +---@param os_slash? boolean use os filesystem slash instead of posix slash ---@return string -M.addslash = function(path) - if not vim.endswith(path, "/") then - return path .. "/" +M.addslash = function(path, os_slash) + local slash = "/" + if os_slash and require("oil.fs").is_windows then + slash = "\\" + end + + if not vim.endswith(path, slash) then + return path .. slash else return path end