From 7b7fb56c4e33d3e2a080ac8959140808652ae1c1 Mon Sep 17 00:00:00 2001 From: kiyan42 Date: Tue, 18 Feb 2020 14:26:40 +0100 Subject: [PATCH] better format --- README.md | 3 ++- lua/lib/format.lua | 38 +++++++++++++++++++++++++++++++++++--- plugin/tree.vim | 7 +++++-- 3 files changed, 42 insertions(+), 6 deletions(-) diff --git a/README.md b/README.md index 86069bd2..bb9b05f6 100644 --- a/README.md +++ b/README.md @@ -16,7 +16,7 @@ - [x] add / rename / delete file in directory - [ ] update tree when altering the FS -- [x] syntax highlighting +- [x] syntax highlighting ([exa](https://github.com/ogham/exa) like) and file icons with vim-devicons - [ ] simple git integration (color of file changing when staged/changed) - [ ] quickly find file in the directory structure @@ -26,3 +26,4 @@ - [ ] buffer / window should always stay on the left and never change size (open a file with only the tree open to reproduce this bug) - [ ] buffer / window should not disappear when only the tree is opened +- [ ] symbolic links diff --git a/lua/lib/format.lua b/lua/lib/format.lua index 8ed7f663..40d8dc30 100644 --- a/lua/lib/format.lua +++ b/lua/lib/format.lua @@ -20,8 +20,36 @@ local function default_icons(_, isdir, open) return "" end +local function create_matcher(arr) + return function(name) + for _, n in pairs(arr) do + if string.match(name, n) then return true end + end + return false + end +end + +local is_special = create_matcher({ + 'README', + 'readme', + 'Makefile', + 'Cargo%.toml', +}) + +local is_pic = create_matcher({ + '%.jpe?g$', + '%.png', + '%.gif' +}) + +local function is_executable(name) + return api.nvim_call_function('executable', { name }) == 1 +end + local function dev_icons(pathname, isdir, open) - if isdir == true then return default_icons(pathname, isdir, open) end + if isdir == true or is_special(pathname) == true or is_executable(pathname) == true or is_pic(pathname) == true then + return default_icons(pathname, isdir, open) + end local icon = api.nvim_call_function('WebDevIconsGetFileTypeSymbol', { pathname, isdir }) if icon == "" then return "" end @@ -78,8 +106,6 @@ local HIGHLIGHT_GROUPS = { ['^.*%.jsx$'] = 'ReactFile'; ['^.*%.tsx$'] = 'ReactFile'; ['^.*%.html?$'] = 'HtmlFile'; - ['^.*%.png$'] = 'ImageFile'; - ['^.*%.jpe?g$'] = 'ImageFile'; } local function highlight_line(buffer) @@ -95,6 +121,12 @@ local function highlight_line(buffer) else highlight('LuaTreeFolderName', line, 0, -1) end + elseif is_special(node.name) == true then + highlight('LuaTreeSpecialFile', line, 0, -1) + elseif is_executable(node.path .. node.name) then + highlight('LuaTreeExecFile', line, 0, -1) + elseif is_pic(node.path .. node.name) then + highlight('LuaTreeImageFile', line, 0, -1) else for k, v in pairs(HIGHLIGHT_GROUPS) do if string.match(node.name, k) ~= nil then diff --git a/plugin/tree.vim b/plugin/tree.vim index e23fa74e..be1ad67e 100644 --- a/plugin/tree.vim +++ b/plugin/tree.vim @@ -9,12 +9,15 @@ let g:loaded_netrwPlugin = 1 " Disable netrw hi def link LuaTreePopup Normal hi def LuaTreeEndOfBuffer guifg=bg -execute 'hi def LuaTreeFolderName guifg='.g:terminal_color_4.' gui=bold' +execute 'hi def LuaTreeFolderName gui=bold guifg='.g:terminal_color_4 execute 'hi def LuaTreeFolderIcon guifg='.g:terminal_color_11 +execute 'hi def LuaTreeExecFile gui=bold guifg='.g:terminal_color_2 +execute 'hi def LuaTreeSpecialFile gui=bold,underline guifg='.g:terminal_color_3 +execute 'hi def LuaTreeImageFile gui=bold guifg='.g:terminal_color_5 + execute 'hi def LuaTreeLicenseFile guifg='.g:terminal_color_3 execute 'hi def LuaTreeMarkdownFile guifg='.g:terminal_color_5 -execute 'hi def LuaTreeImageFile guifg='.g:terminal_color_5 execute 'hi def LuaTreeYamlFile guifg='.g:terminal_color_3 execute 'hi def LuaTreeTomlFile guifg='.g:terminal_color_3 execute 'hi def LuaTreeGitignoreFile guifg='.g:terminal_color_3