diff --git a/README.md b/README.md index 91215cce..a2fd49fa 100644 --- a/README.md +++ b/README.md @@ -89,7 +89,8 @@ let g:lua_tree_icons = { \ }, \ 'folder': { \ 'default': "", - \ 'open': "" + \ 'open': "", + \ 'symlink': "", \ } \ } diff --git a/doc/nvim-tree-lua.txt b/doc/nvim-tree-lua.txt index 22458ca1..e24d2e28 100644 --- a/doc/nvim-tree-lua.txt +++ b/doc/nvim-tree-lua.txt @@ -106,7 +106,8 @@ You can set icons for: \ }, \ 'folder': { \ 'default': "", - \ 'open': "" + \ 'open': "", + \ 'symlink': "", \ } \ } diff --git a/lua/lib/config.lua b/lua/lib/config.lua index 767f2bdb..35e2ba7f 100644 --- a/lua/lib/config.lua +++ b/lua/lib/config.lua @@ -15,7 +15,8 @@ function M.get_icon_state() }, folder_icons = { default = "", - open = "" + open = "", + symlink = "", } } diff --git a/lua/lib/lib.lua b/lua/lib/lib.lua index 3d9983b5..50958d01 100644 --- a/lua/lib/lib.lua +++ b/lua/lib/lib.lua @@ -93,7 +93,7 @@ function M.unroll_dir(node) if #node.entries > 0 then renderer.draw(M.Tree, true) else - populate(node.entries, node.absolute_path) + populate(node.entries, node.link_to or node.absolute_path) renderer.draw(M.Tree, true) end end diff --git a/lua/lib/populate.lua b/lua/lib/populate.lua index c8499649..291f9f3e 100644 --- a/lua/lib/populate.lua +++ b/lua/lib/populate.lua @@ -48,10 +48,17 @@ end local function link_new(cwd, name) local absolute_path = cwd..'/'..name local link_to = luv.fs_realpath(absolute_path) + local open, entries + if luv.fs_stat(link_to).type == 'directory' then + open = false + entries = {} + end return { name = name, absolute_path = absolute_path, link_to = link_to, + open = open, + entries = entries, match_name = path_to_matching_str(name), match_path = path_to_matching_str(absolute_path), } diff --git a/lua/lib/renderer.lua b/lua/lib/renderer.lua index 3fdd6807..b37015a6 100644 --- a/lua/lib/renderer.lua +++ b/lua/lib/renderer.lua @@ -16,12 +16,16 @@ local set_folder_hl = function(line, depth, git_icon_len, _, hl_group) end if icon_state.show_folder_icon then - get_folder_icon = function(open) - if open then - return icon_state.icons.folder_icons.open .. " " + get_folder_icon = function(open, is_symlink) + local n = "" + if is_symlink then + n = icon_state.icons.folder_icons.symlink + elseif open then + n = icon_state.icons.folder_icons.open else - return icon_state.icons.folder_icons.default .. " " + n = icon_state.icons.folder_icons.default end + return n.." " end set_folder_hl = function(line, depth, icon_len, name_len, hl_group) table.insert(hl, {hl_group, line, depth+icon_len, depth+icon_len+name_len}) @@ -225,7 +229,7 @@ local function update_draw_data(tree, depth, markers) local git_hl = get_git_hl(node) if node.entries then - local icon = get_folder_icon(node.open) + local icon = get_folder_icon(node.open, node.link_to ~= nil) local git_icon = get_git_icons(node, index, offset, #icon+1) or "" -- INFO: this is mandatory in order to keep gui attributes (bold/italics) set_folder_hl(index, offset, #icon, #node.name+#git_icon, 'LuaTreeFolderName') diff --git a/lua/tree.lua b/lua/tree.lua index b5311a2a..fe26ac6b 100644 --- a/lua/tree.lua +++ b/lua/tree.lua @@ -95,10 +95,8 @@ function M.on_keypress(mode) return end - if node.link_to then + if node.link_to and not node.entries then local stat = luv.fs_stat(node.link_to) - -- TODO: potentially CD here - if stat.type == 'directory' then return end lib.open_file(mode, node.link_to) elseif node.entries ~= nil then lib.unroll_dir(node)