add symlink handling
This commit is contained in:
@@ -14,6 +14,7 @@ local colors = {
|
||||
}
|
||||
|
||||
local HIGHLIGHTS = {
|
||||
Symlink = { gui = 'bold', fg = colors.cyan },
|
||||
FolderName = { gui = 'bold', fg = colors.blue },
|
||||
FolderIcon = { fg = colors.orange },
|
||||
|
||||
|
||||
@@ -73,10 +73,13 @@ local function format_tree(tree)
|
||||
local padding = get_padding(node.depth)
|
||||
local git = node.git
|
||||
local icon = ""
|
||||
if node.icon == true then
|
||||
local name = node.name
|
||||
if node.link == true then
|
||||
name = name .. ' ➛ ' .. node.linkto
|
||||
elseif node.icon == true then
|
||||
icon = get_icon(node.path .. node.name, node.dir, node.open)
|
||||
end
|
||||
dirs[i] = padding .. icon .. git .. node.name
|
||||
dirs[i] = padding .. icon .. git .. name
|
||||
end
|
||||
|
||||
return dirs
|
||||
@@ -120,6 +123,9 @@ local function highlight_line(buffer)
|
||||
highlight('LuaTreeFolderIcon', line, 0, text_start)
|
||||
highlight('LuaTreeFolderName', line, text_start + gitlen, -1)
|
||||
|
||||
elseif node.link == true then
|
||||
highlight('LuaTreeSymlink', line, 0, -1)
|
||||
|
||||
elseif is_special(node.name) == true then
|
||||
text_start = text_start - 4
|
||||
highlight('LuaTreeSpecialFile', line, text_start + gitlen, -1)
|
||||
|
||||
@@ -6,10 +6,19 @@ local get_git_attr = require 'lib/git'.get_git_attr
|
||||
local Tree = {}
|
||||
|
||||
local function is_dir(path)
|
||||
local stat = vim.loop.fs_stat(path)
|
||||
local stat = vim.loop.fs_lstat(path)
|
||||
return stat and stat.type == 'directory' or false
|
||||
end
|
||||
|
||||
local function is_symlink(path)
|
||||
local stat = vim.loop.fs_lstat(path)
|
||||
return stat and stat.type == 'link' or false
|
||||
end
|
||||
|
||||
local function link_to(path)
|
||||
return vim.loop.fs_readlink(path) or ''
|
||||
end
|
||||
|
||||
local function check_dir_access(path)
|
||||
return vim.loop.fs_access(path, 'R') == true
|
||||
end
|
||||
@@ -46,11 +55,16 @@ local function create_nodes(path, relpath, depth, dirs)
|
||||
if not string.find(relpath, '^.*/$') and depth > 0 then relpath = relpath .. '/' end
|
||||
|
||||
for i, name in pairs(dirs) do
|
||||
local dir = is_dir(path..name)
|
||||
local full_path = path..name
|
||||
local dir = is_dir(full_path)
|
||||
local link = is_symlink(full_path)
|
||||
local linkto = link == true and link_to(full_path) or nil
|
||||
local rel_path = relpath ..name
|
||||
tree[i] = {
|
||||
path = path,
|
||||
relpath = rel_path,
|
||||
link = link,
|
||||
linkto = linkto,
|
||||
name = name,
|
||||
depth = depth,
|
||||
dir = dir,
|
||||
@@ -137,4 +151,5 @@ return {
|
||||
refresh_tree = refresh_tree;
|
||||
open_dir = open_dir;
|
||||
check_dir_access = check_dir_access;
|
||||
is_dir = is_dir;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user