diff options
| author | Fasamii <fasami0512@gmail.com> | 2026-02-07 18:19:41 +0100 |
|---|---|---|
| committer | Fasamii <fasami0512@gmail.com> | 2026-02-07 18:19:41 +0100 |
| commit | ca7c9de0ee9cf584eadf7100d0c95c9eabafd451 (patch) | |
| tree | 93c16127c92b14e702bd43d586074bc78d4f1680 | |
| parent | 87a3aa893687bdeb75d7cef7b60d254a51500248 (diff) | |
| download | netrw-icons.nvim-ca7c9de0ee9cf584eadf7100d0c95c9eabafd451.tar.gz netrw-icons.nvim-ca7c9de0ee9cf584eadf7100d0c95c9eabafd451.tar.bz2 netrw-icons.nvim-ca7c9de0ee9cf584eadf7100d0c95c9eabafd451.tar.xz netrw-icons.nvim-ca7c9de0ee9cf584eadf7100d0c95c9eabafd451.tar.zst | |
Support for netrw_liststyle 0 and 1
| -rw-r--r-- | README.md | 10 | ||||
| -rw-r--r-- | lua/netrw-icons/init.lua | 7 | ||||
| -rw-r--r-- | lua/netrw-icons/parse.lua | 163 |
3 files changed, 74 insertions, 106 deletions
@@ -141,16 +141,18 @@ require("netrw-icons").setup({ ## Supported Netrw List Styles Currently, this plugin supports: -- **Style 3** (tree view): `let g:netrw_liststyle = 3` +- **Style 0**: `let g:netrw_liststyle = 0` +- **Style 1**: `let g:netrw_liststyle = 1` +- **Style 3**: `let g:netrw_liststyle = 3` -To enable tree view in netrw, add to your config: +To set style of netrw: ```vim " In init.vim -let g:netrw_liststyle = 3 +let g:netrw_liststyle = 3 " or 0 or 1 ``` ```lua -- In init.lua -vim.g.netrw_liststyle = 3 +vim.g.netrw_liststyle = 3 -- or 0 or 1 ``` diff --git a/lua/netrw-icons/init.lua b/lua/netrw-icons/init.lua index 683cad6..8b4a575 100644 --- a/lua/netrw-icons/init.lua +++ b/lua/netrw-icons/init.lua @@ -159,12 +159,9 @@ function M.setup(options) return end - -- if vim.b.netrw_liststyle ~= 0 and vim.b.netrw_liststyle ~= 1 and vim.b.netrw_liststyle ~= 3 then - if vim.b.netrw_liststyle ~= 3 then - return + if vim.b.netrw_liststyle == 0 or vim.b.netrw_liststyle == 1 or vim.b.netrw_liststyle == 3 then + draw(args.buf) end - - draw(args.buf) end }) end diff --git a/lua/netrw-icons/parse.lua b/lua/netrw-icons/parse.lua index 5245645..fbd9da1 100644 --- a/lua/netrw-icons/parse.lua +++ b/lua/netrw-icons/parse.lua @@ -15,101 +15,66 @@ M.TYPE_SYMLINK = 3 ---@alias rwNode{name:string, icon:number, type:number} --- ---@param line string --- ---@param curdir string --- ---@return rwNode|nil --- local parse_liststyle_0 = function(line, curdir) --- local _, _, node, link = string.find(line, "^(.+)@\t%s*%-%->%s*(.+)") --- if node then --- return { --- dir = curdir, --- icon_col = 0, --- name_col = 0, --- lsp_col = #node, --- node = node, --- extension = vim.fn.fnamemodify(node, ":e"), --- link = link, --- type = M.TYPE_SYMLINK, --- } --- end --- --- local _, _, dir = string.find(line, "^(.*)/") --- if dir then --- return { --- dir = curdir, --- icon_col = 0, --- name_col = 0, --- lsp_col = #dir + 1, -- +1 for the "/" --- node = dir, --- type = M.TYPE_DIR, --- } --- end --- --- local ext = vim.fn.fnamemodify(line, ":e") --- local clean_line = line --- if string.sub(ext, -1) == "*" then --- ext = string.sub(ext, 1, -2) --- clean_line = string.sub(line, 1, -2) --- end --- --- return { --- dir = curdir, --- icon_col = 0, --- name_col = 0, --- lsp_col = #clean_line, --- node = clean_line, --- extension = ext, --- type = M.TYPE_FILE, --- } --- end --- --- ---@param line string --- ---@param curdir string --- ---@return rwNode|nil --- local parse_liststyle_1 = function(line, curdir) --- local _, _, node, link = string.find(line, "^(.+)@%s+") --- if node then --- return { --- dir = curdir, --- icon_col = 0, --- name_col = 0, --- lsp_col = #node, --- node = node, --- extension = vim.fn.fnamemodify(node, ":e"), --- link = link, --- type = M.TYPE_SYMLINK, --- } --- end --- --- local _, _, dir = string.find(line, "^(.*)/") --- if dir then --- return { --- dir = curdir, --- icon_col = 0, --- name_col = 0, --- lsp_col = #dir + 1, --- node = dir, --- type = M.TYPE_DIR, --- } --- end --- --- local file = vim.fn.substitute(line, "^\\(\\%(\\S\\+ \\)*\\S\\+\\).\\{-}$", "\\1", "e") --- local ext = vim.fn.fnamemodify(file, ":e") --- if string.sub(ext, -1) == "*" then --- ext = string.sub(ext, 1, -2) --- file = string.sub(file, 1, -2) --- end --- --- return { --- dir = curdir, --- icon_col = 0, --- name_col = 0, --- lsp_col = #file, --- node = file, --- extension = ext, --- type = M.TYPE_FILE, --- } --- end +---@param line string +---@param curdir string +---@return rwNode|nil +local parse_liststyle_0 = function(line) + local current_dir = vim.b.netrw_curdir; + local type = M.TYPE_FILE; + + local name = line; + + if name:sub(-1) == "*" then + type = M.TYPE_EXE; + end + + local _, _, link, link_target = string.find(line, "^(.+)@\t%s*%-%->%s*(.+)") + if link then + type = M.TYPE_SYMLINK; + name = link_target; + end + + local _, _, dir = string.find(line, "^(.*)/") + if dir then + type = M.TYPE_DIR; + end + + return { + name = name, + icon = 0, + type = type, + } +end + +---@param line string +---@return rwNode|nil +local parse_liststyle_1 = function(line) + local current_dir = vim.b.netrw_curdier; + local type = M.TYPE_FILE; + + local name = line:match("^(%S+)") + + if name:sub(-1) == "*" then + type = M.TYPE_EXE; + end + + local _, _, link, link_target = string.find(line, "^(.+)@%s+") + if link then + type = M.TYPE_SYMLINK; + name = link_target; + end + + local _, _, dir = string.find(line, "^(.*)/") + if dir then + type = M.TYPE_DIR; + end + + return { + name = name, + icon = 0, + type = type, + } +end ---@param line string ---@return rwNode|nil @@ -156,8 +121,12 @@ M.get_node = function(line) local liststyle = vim.b.netrw_liststyle - if liststyle == 3 then - return parse_liststyle_3(line) + if liststyle == 0 then + return parse_liststyle_0(line); + elseif liststyle == 1 then + return parse_liststyle_1(line); + elseif liststyle == 3 then + return parse_liststyle_3(line); end return nil |
