This commit is contained in:
@@ -4,6 +4,7 @@ local watch = require "nvim-tree.explorer.watch"
|
|||||||
|
|
||||||
local M = {
|
local M = {
|
||||||
is_windows = vim.fn.has "win32" == 1,
|
is_windows = vim.fn.has "win32" == 1,
|
||||||
|
is_wsl = vim.fn.has "wsl" == 1,
|
||||||
}
|
}
|
||||||
|
|
||||||
function M.folder(parent, absolute_path, name)
|
function M.folder(parent, absolute_path, name)
|
||||||
@@ -24,9 +25,19 @@ function M.folder(parent, absolute_path, name)
|
|||||||
}
|
}
|
||||||
end
|
end
|
||||||
|
|
||||||
function M.is_executable(absolute_path, ext)
|
function M.is_executable(parent, absolute_path, ext)
|
||||||
if M.is_windows then
|
if M.is_windows then
|
||||||
return utils.is_windows_exe(ext)
|
return utils.is_windows_exe(ext)
|
||||||
|
elseif M.is_wsl then
|
||||||
|
if parent.is_wsl_windows_fs_path == nil then
|
||||||
|
-- Evaluate lazily when needed and do so only once for each parent
|
||||||
|
-- as 'wslpath' calls can get expensive in highly populated directories.
|
||||||
|
parent.is_wsl_windows_fs_path = utils.is_wsl_windows_fs_path(absolute_path)
|
||||||
|
end
|
||||||
|
|
||||||
|
if parent.is_wsl_windows_fs_path then
|
||||||
|
return utils.is_wsl_windows_fs_exe(ext)
|
||||||
|
end
|
||||||
end
|
end
|
||||||
return uv.fs_access(absolute_path, "X")
|
return uv.fs_access(absolute_path, "X")
|
||||||
end
|
end
|
||||||
@@ -37,7 +48,7 @@ function M.file(parent, absolute_path, name)
|
|||||||
return {
|
return {
|
||||||
type = "file",
|
type = "file",
|
||||||
absolute_path = absolute_path,
|
absolute_path = absolute_path,
|
||||||
executable = M.is_executable(absolute_path, ext),
|
executable = M.is_executable(parent, absolute_path, ext),
|
||||||
extension = ext,
|
extension = ext,
|
||||||
fs_stat = uv.fs_stat(absolute_path),
|
fs_stat = uv.fs_stat(absolute_path),
|
||||||
name = name,
|
name = name,
|
||||||
|
|||||||
@@ -86,7 +86,7 @@ function M.reload(node, status)
|
|||||||
else
|
else
|
||||||
local n = nodes_by_path[abs]
|
local n = nodes_by_path[abs]
|
||||||
if n then
|
if n then
|
||||||
n.executable = builders.is_executable(abs, n.extension or "")
|
n.executable = builders.is_executable(n.parent, abs, n.extension or "")
|
||||||
n.fs_stat = fs_stat_cached(abs)
|
n.fs_stat = fs_stat_cached(abs)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|||||||
@@ -10,6 +10,7 @@ local M = {
|
|||||||
}
|
}
|
||||||
|
|
||||||
M.is_windows = vim.fn.has "win32" == 1 or vim.fn.has "win32unix" == 1
|
M.is_windows = vim.fn.has "win32" == 1 or vim.fn.has "win32unix" == 1
|
||||||
|
M.is_wsl = vim.fn.has "wsl" == 1
|
||||||
|
|
||||||
function M.path_to_matching_str(path)
|
function M.path_to_matching_str(path)
|
||||||
return path:gsub("(%-)", "(%%-)"):gsub("(%.)", "(%%.)"):gsub("(%_)", "(%%_)")
|
return path:gsub("(%-)", "(%%-)"):gsub("(%.)", "(%%.)"):gsub("(%_)", "(%%_)")
|
||||||
@@ -171,8 +172,11 @@ end
|
|||||||
---@return boolean
|
---@return boolean
|
||||||
function M.is_windows_exe(ext)
|
function M.is_windows_exe(ext)
|
||||||
if not M.pathexts then
|
if not M.pathexts then
|
||||||
local PATHEXT = vim.env.PATHEXT or ""
|
if not vim.env.PATHEXT then
|
||||||
local wexe = vim.split(PATHEXT:gsub("%.", ""), ";")
|
return false
|
||||||
|
end
|
||||||
|
|
||||||
|
local wexe = vim.split(vim.env.PATHEXT:gsub("%.", ""), ";")
|
||||||
M.pathexts = {}
|
M.pathexts = {}
|
||||||
for _, v in pairs(wexe) do
|
for _, v in pairs(wexe) do
|
||||||
M.pathexts[v] = true
|
M.pathexts[v] = true
|
||||||
@@ -182,6 +186,44 @@ function M.is_windows_exe(ext)
|
|||||||
return M.pathexts[ext:upper()]
|
return M.pathexts[ext:upper()]
|
||||||
end
|
end
|
||||||
|
|
||||||
|
--- Check whether path maps to Windows filesystem mounted by WSL
|
||||||
|
-- @param path string
|
||||||
|
-- @return boolean
|
||||||
|
function M.is_wsl_windows_fs_path(path)
|
||||||
|
-- Run 'wslpath' command to try translating WSL path to Windows path.
|
||||||
|
-- Consume stderr output as well because 'wslpath' can produce permission
|
||||||
|
-- errors on some files (e.g. temporary files in root of system drive).
|
||||||
|
local handle = io.popen('wslpath -w "' .. path .. '" 2>/dev/null')
|
||||||
|
if handle then
|
||||||
|
local output = handle:read "*a"
|
||||||
|
handle:close()
|
||||||
|
|
||||||
|
return string.find(output, "^\\\\wsl$\\") == nil
|
||||||
|
end
|
||||||
|
|
||||||
|
return false
|
||||||
|
end
|
||||||
|
|
||||||
|
--- Check whether extension is Windows executable under WSL
|
||||||
|
-- @param ext string
|
||||||
|
-- @return boolean
|
||||||
|
function M.is_wsl_windows_fs_exe(ext)
|
||||||
|
if not vim.env.PATHEXT then
|
||||||
|
-- Extract executable extensions from within WSL.
|
||||||
|
-- Redirect stderr to null to silence warnings when
|
||||||
|
-- Windows command is executed from Linux filesystem:
|
||||||
|
-- > CMD.EXE was started with the above path as the current directory.
|
||||||
|
-- > UNC paths are not supported. Defaulting to Windows directory.
|
||||||
|
local handle = io.popen 'cmd.exe /c "echo %PATHEXT%" 2>/dev/null'
|
||||||
|
if handle then
|
||||||
|
vim.env.PATHEXT = handle:read "*a"
|
||||||
|
handle:close()
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
return M.is_windows_exe(ext)
|
||||||
|
end
|
||||||
|
|
||||||
function M.rename_loaded_buffers(old_path, new_path)
|
function M.rename_loaded_buffers(old_path, new_path)
|
||||||
for _, buf in pairs(a.nvim_list_bufs()) do
|
for _, buf in pairs(a.nvim_list_bufs()) do
|
||||||
if a.nvim_buf_is_loaded(buf) then
|
if a.nvim_buf_is_loaded(buf) then
|
||||||
|
|||||||
Reference in New Issue
Block a user