local _icons = require "nvim-tree.renderer.icons" local utils = require "nvim-tree.utils" local M = {} local function build_icons_table() return { ["M "] = { { icon = M.icon_state.icons.git_icons.staged, hl = "NvimTreeGitStaged" } }, [" M"] = { { icon = M.icon_state.icons.git_icons.unstaged, hl = "NvimTreeGitDirty" } }, ["C "] = { { icon = M.icon_state.icons.git_icons.staged, hl = "NvimTreeGitStaged" } }, [" C"] = { { icon = M.icon_state.icons.git_icons.unstaged, hl = "NvimTreeGitDirty" } }, ["CM"] = { { icon = M.icon_state.icons.git_icons.unstaged, hl = "NvimTreeGitDirty" } }, [" T"] = { { icon = M.icon_state.icons.git_icons.unstaged, hl = "NvimTreeGitDirty" } }, ["MM"] = { { icon = M.icon_state.icons.git_icons.staged, hl = "NvimTreeGitStaged" }, { icon = M.icon_state.icons.git_icons.unstaged, hl = "NvimTreeGitDirty" }, }, ["MD"] = { { icon = M.icon_state.icons.git_icons.staged, hl = "NvimTreeGitStaged" }, }, ["A "] = { { icon = M.icon_state.icons.git_icons.staged, hl = "NvimTreeGitStaged" }, }, ["AD"] = { { icon = M.icon_state.icons.git_icons.staged, hl = "NvimTreeGitStaged" }, }, [" A"] = { { icon = M.icon_state.icons.git_icons.untracked, hl = "NvimTreeGitNew" }, }, -- not sure about this one ["AA"] = { { icon = M.icon_state.icons.git_icons.unmerged, hl = "NvimTreeGitMerge" }, { icon = M.icon_state.icons.git_icons.untracked, hl = "NvimTreeGitNew" }, }, ["AU"] = { { icon = M.icon_state.icons.git_icons.unmerged, hl = "NvimTreeGitMerge" }, { icon = M.icon_state.icons.git_icons.untracked, hl = "NvimTreeGitNew" }, }, ["AM"] = { { icon = M.icon_state.icons.git_icons.staged, hl = "NvimTreeGitStaged" }, { icon = M.icon_state.icons.git_icons.unstaged, hl = "NvimTreeGitDirty" }, }, ["??"] = { { icon = M.icon_state.icons.git_icons.untracked, hl = "NvimTreeGitNew" } }, ["R "] = { { icon = M.icon_state.icons.git_icons.renamed, hl = "NvimTreeGitRenamed" } }, [" R"] = { { icon = M.icon_state.icons.git_icons.renamed, hl = "NvimTreeGitRenamed" } }, ["RM"] = { { icon = M.icon_state.icons.git_icons.unstaged, hl = "NvimTreeGitDirty" }, { icon = M.icon_state.icons.git_icons.renamed, hl = "NvimTreeGitRenamed" }, }, ["UU"] = { { icon = M.icon_state.icons.git_icons.unmerged, hl = "NvimTreeGitMerge" } }, ["UD"] = { { icon = M.icon_state.icons.git_icons.unmerged, hl = "NvimTreeGitMerge" } }, ["UA"] = { { icon = M.icon_state.icons.git_icons.unmerged, hl = "NvimTreeGitMerge" } }, [" D"] = { { icon = M.icon_state.icons.git_icons.deleted, hl = "NvimTreeGitDeleted" } }, ["D "] = { { icon = M.icon_state.icons.git_icons.deleted, hl = "NvimTreeGitDeleted" } }, ["RD"] = { { icon = M.icon_state.icons.git_icons.deleted, hl = "NvimTreeGitDeleted" } }, ["DD"] = { { icon = M.icon_state.icons.git_icons.deleted, hl = "NvimTreeGitDeleted" } }, ["DU"] = { { icon = M.icon_state.icons.git_icons.deleted, hl = "NvimTreeGitDeleted" }, { icon = M.icon_state.icons.git_icons.unmerged, hl = "NvimTreeGitMerge" }, }, ["!!"] = { { icon = M.icon_state.icons.git_icons.ignored, hl = "NvimTreeGitIgnored" } }, dirty = { { icon = M.icon_state.icons.git_icons.unstaged, hl = "NvimTreeGitDirty" } }, } end local function empty() return "" end local function nil_() end local function warn_status(git_status) utils.warn( 'Unrecognized git state "' .. git_status .. '". Please open up an issue on https://github.com/kyazdani42/nvim-tree.lua/issues with this message.' ) end local function get_icons_(node, line, depth, icon_len, hl) local git_status = node.git_status if not git_status then return "" end local icon = "" local icons = M.git_icons[git_status] if not icons then if vim.g.nvim_tree_git_hl ~= 1 then warn_status(git_status) end return "" end for _, v in ipairs(icons) do if #v.icon > 0 then table.insert(hl, { v.hl, line, depth + icon_len + #icon, depth + icon_len + #icon + #v.icon }) icon = icon .. v.icon .. M.icon_padding end end return icon end local git_hl = { ["M "] = "NvimTreeFileStaged", ["C "] = "NvimTreeFileStaged", ["AA"] = "NvimTreeFileStaged", ["AD"] = "NvimTreeFileStaged", ["MD"] = "NvimTreeFileStaged", [" M"] = "NvimTreeFileDirty", ["CM"] = "NvimTreeFileDirty", [" C"] = "NvimTreeFileDirty", [" T"] = "NvimTreeFileDirty", ["MM"] = "NvimTreeFileDirty", ["AM"] = "NvimTreeFileDirty", dirty = "NvimTreeFileDirty", ["A "] = "NvimTreeFileNew", ["??"] = "NvimTreeFileNew", ["AU"] = "NvimTreeFileMerge", ["UU"] = "NvimTreeFileMerge", ["UD"] = "NvimTreeFileMerge", ["DU"] = "NvimTreeFileMerge", ["UA"] = "NvimTreeFileMerge", [" D"] = "NvimTreeFileDeleted", ["DD"] = "NvimTreeFileDeleted", ["RD"] = "NvimTreeFileDeleted", ["D "] = "NvimTreeFileDeleted", ["R "] = "NvimTreeFileRenamed", ["RM"] = "NvimTreeFileRenamed", [" R"] = "NvimTreeFileRenamed", ["!!"] = "NvimTreeGitIgnored", [" A"] = "none", } local function get_highlight_(node) local git_status = node.git_status if not git_status then return end return git_hl[git_status] end function M.get_icons() return empty() end function M.get_highlight() return nil_() end M.icon_padding = vim.g.nvim_tree_icon_padding or " " M.icon_state = _icons.get_config() M.git_icons = build_icons_table() function M.reload() M.icon_state = _icons.get_config() M.icon_padding = vim.g.nvim_tree_icon_padding or " " M.git_icons = build_icons_table() if M.icon_state.show_git_icon then M.get_icons = get_icons_ else M.get_icons = empty end if vim.g.nvim_tree_git_hl == 1 then M.get_highlight = get_highlight_ else M.get_highlight = nil_ end end return M