Using "vim.env.PATHEXT" to determine Windows executables. (#784)
This commit is contained in:
@@ -4,7 +4,8 @@ local luv = vim.loop
|
||||
local utils = require'nvim-tree.utils'
|
||||
|
||||
local M = {
|
||||
ignore_list = {}
|
||||
ignore_list = {},
|
||||
is_windows = vim.fn.has('win32') == 1
|
||||
}
|
||||
|
||||
local function dir_new(cwd, name, status, parent_ignored)
|
||||
@@ -34,12 +35,18 @@ end
|
||||
|
||||
local function file_new(cwd, name, status, parent_ignored)
|
||||
local absolute_path = utils.path_join({cwd, name})
|
||||
local is_exec = luv.fs_access(absolute_path, 'X')
|
||||
local ext = string.match(name, ".?[^.]+%.(.*)") or ""
|
||||
local is_exec
|
||||
if M.is_windows then
|
||||
is_exec = utils.is_windows_exe(ext)
|
||||
else
|
||||
is_exec = luv.fs_access(absolute_path, 'X')
|
||||
end
|
||||
return {
|
||||
name = name,
|
||||
absolute_path = absolute_path,
|
||||
executable = is_exec,
|
||||
extension = string.match(name, ".?[^.]+%.(.*)") or "",
|
||||
extension = ext,
|
||||
git_status = parent_ignored and '!!' or status.files and status.files[absolute_path],
|
||||
}
|
||||
end
|
||||
|
||||
@@ -169,4 +169,17 @@ function M.merge_sort(t, comparator)
|
||||
split_merge(t, 1, #t, comparator)
|
||||
end
|
||||
|
||||
---Matching executable files in Windows.
|
||||
---@param ext string
|
||||
---@return boolean
|
||||
local wexe = vim.split(vim.env.PATHEXT:gsub('%.', ''), ';')
|
||||
local pathexts = {}
|
||||
for _, v in pairs(wexe) do
|
||||
pathexts[v] = true
|
||||
end
|
||||
|
||||
function M.is_windows_exe(ext)
|
||||
return pathexts[ext:upper()]
|
||||
end
|
||||
|
||||
return M
|
||||
|
||||
Reference in New Issue
Block a user