Skip to content

Commit 04ca421

Browse files
committed
feat: add symbols for git status component, closes #148
1 parent 537f679 commit 04ca421

File tree

6 files changed

+138
-22
lines changed

6 files changed

+138
-22
lines changed

.gitignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,3 +41,6 @@ luac.out
4141

4242
# Vim tag files
4343
tags
44+
45+
#example
46+
ignored

doc/neo-tree.txt

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -429,6 +429,48 @@ config when calling the setup function. To just disable colors on file or
429429
directory names, you can set `use_git_status_colors = false` in the `name`
430430
component of your renderer(s).
431431

432+
Starting with 2.0, this will display symbols by default. The default symbols
433+
will require a nerd font to be installed. To change these symbols, you can set
434+
the following properties:
435+
>
436+
require("neo-tree").setup({
437+
default_component_configs = {
438+
symbols = {
439+
added = "✚",
440+
conflict = "",
441+
deleted = "✖",
442+
ignored = "○",
443+
modified = "",
444+
renamed = "🠊",
445+
staged = "",
446+
unstaged = "",
447+
untracked = "",
448+
}
449+
}
450+
})
451+
<
452+
To change the color of these symbols, you can edit the corresponding highlight
453+
groups:
454+
455+
NeoTreeGitAdded
456+
NeoTreeGitConflict
457+
NeoTreeGitDeleted
458+
NeoTreeGitIgnored
459+
NeoTreeGitModified
460+
NeoTreeGitUntracked
461+
462+
To revert to the previous behavior of passing the git status through as-is
463+
with codes like `[M ]` for changed/unstaged, and `[ M]` for changed/staged,
464+
you can set the `symbols` property to nil or false:
465+
>
466+
require("neo-tree").setup({
467+
default_component_configs = {
468+
git_status = {
469+
symbols = false
470+
}
471+
}
472+
})
473+
<
432474
See also: |neo-tree-git-status-source|
433475

434476

@@ -529,6 +571,7 @@ NeoTreeFilterTerm The filter term, as displayed in the root node.
529571
NeoTreeFloatBorder The border for pop-up windows.
530572
NeoTreeGitAdded File name when the git status is added.
531573
NeoTreeGitConflict File name when the git status is conflict.
574+
NeoTreeGitDeleted File name when the git status is deleted.
532575
NeoTreeGitIgnored File name when the git status is ignored.
533576
NeoTreeGitModified File name when the git status is modified.
534577
NeoTreeGitUntracked File name when the git status is untracked.

lua/neo-tree/defaults.lua

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,18 @@ local config = {
6868
use_git_status_colors = true,
6969
},
7070
git_status = {
71-
highlight = "NeoTreeDimText",
71+
symbols = {
72+
added = "",
73+
--conflict = "ﲅ",
74+
conflict = "",
75+
deleted = "",
76+
ignored = "",
77+
modified = "",
78+
renamed = "🠊",
79+
staged = "",
80+
unstaged = "",
81+
untracked = "",
82+
}
7283
},
7384
},
7485
filesystem = {

lua/neo-tree/sources/common/components.lua

Lines changed: 72 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
-- highlight: The highlight group to apply to this text.
1212

1313
local highlights = require("neo-tree.ui.highlights")
14+
local utils = require("neo-tree.utils")
1415

1516
local M = {}
1617

@@ -86,25 +87,83 @@ M.git_status = function(config, node, state)
8687
end
8788
end
8889

89-
local highlight = highlights.FILE_NAME
90+
local symbols = config.symbols or {}
91+
local status_symbol
92+
local status_highlt = highlights.FILE_NAME
93+
local staged_symbol = symbols.unstaged
94+
local staged_highlt = highlights.GIT_CONFLICT
95+
96+
if git_status:sub(2, 2) == " " then
97+
staged_symbol = symbols.staged
98+
staged_highlt = highlights.GIT_ADDED
99+
end
100+
90101
if git_status:match("?$") then
91-
highlight = highlights.GIT_UNTRACKED
92-
elseif git_status:match("U") then
93-
highlight = highlights.GIT_CONFLICT
102+
staged_symbol = nil
103+
staged_highlt = highlights.GIT_UNTRACKED
104+
status_symbol = symbols.untracked
105+
status_highlt = highlights.GIT_UNTRACKED
106+
-- all variations of merge conflicts
107+
elseif git_status == "DD" then
108+
staged_symbol = symbols.conflict
109+
staged_highlt = highlights.GIT_CONFLICT
110+
status_symbol = symbols.deleted
111+
status_highlt = highlights.GIT_CONFLICT
112+
elseif git_status == "UU" then
113+
staged_symbol = symbols.conflict
114+
staged_highlt = highlights.GIT_CONFLICT
115+
status_symbol = symbols.modified
116+
status_highlt = highlights.GIT_CONFLICT
94117
elseif git_status == "AA" then
95-
highlight = highlights.GIT_CONFLICT
118+
staged_symbol = symbols.conflict
119+
staged_highlt = highlights.GIT_CONFLICT
120+
status_symbol = symbols.added
121+
status_highlt = highlights.GIT_CONFLICT
122+
elseif git_status:match("U") then
123+
staged_symbol = symbols.conflict
124+
staged_highlt = highlights.GIT_CONFLICT
125+
if git_status:match("A") then
126+
status_symbol = symbols.added
127+
elseif git_status:match("D") then
128+
status_symbol = symbols.deleted
129+
end
130+
status_highlt = highlights.GIT_CONFLICT
131+
-- end merge conflict section
96132
elseif git_status:match("M") then
97-
highlight = highlights.GIT_MODIFIED
98-
elseif git_status:match("[ACRT]") then
99-
highlight = highlights.GIT_ADDED
133+
status_symbol = symbols.modified
134+
status_highlt = highlights.GIT_MODIFIED
135+
elseif git_status:match("R") then
136+
status_symbol = symbols.renamed
137+
status_highlt = highlights.GIT_MODIFIED
138+
elseif git_status:match("[ACT]") then
139+
status_symbol = symbols.added
140+
status_highlt = highlights.GIT_ADDED
100141
elseif git_status:match("!") then
101-
highlight = highlights.GIT_IGNORED
142+
staged_symbol = nil
143+
status_symbol = symbols.ignored
144+
status_highlt = highlights.GIT_IGNORED
145+
end
146+
147+
if status_symbol then
148+
local components = {}
149+
components[1] = {
150+
text = " " .. status_symbol,
151+
highlight = status_highlt,
152+
}
153+
if staged_symbol then
154+
components[2] = {
155+
text = " " .. staged_symbol,
156+
highlight = staged_highlt,
157+
}
158+
end
159+
return components
160+
else
161+
return {
162+
text = " [" .. git_status .. "]",
163+
highlight = config.highlight or status_highlt,
164+
}
102165
end
103166

104-
return {
105-
text = " [" .. git_status .. "]",
106-
highlight = config.highlight or highlight,
107-
}
108167
end
109168

110169
M.filtered_by = function(config, node, state)

lua/neo-tree/ui/highlights.lua

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ M.FILTER_TERM = "NeoTreeFilterTerm"
1414
M.FLOAT_BORDER = "NeoTreeFloatBorder"
1515
M.GIT_ADDED = "NeoTreeGitAdded"
1616
M.GIT_CONFLICT = "NeoTreeGitConflict"
17+
M.GIT_DELETED = "NeoTreeGitDeleted"
1718
M.GIT_IGNORED = "NeoTreeGitIgnored"
1819
M.GIT_MODIFIED = "NeoTreeGitModified"
1920
M.GIT_UNTRACKED = "NeoTreeGitUntracked"
@@ -41,6 +42,8 @@ end
4142
--is not defined and it is not linked to another group.
4243
---@param foreground string The foreground color to use, in hex, if the highlight group
4344
--is not defined and it is not linked to another group.
45+
---@gui string The gui to use, if the highlight group is not defined and it is not linked
46+
--to another group.
4447
---@return table table The highlight group values.
4548
local function create_highlight_group(hl_group_name, link_to_if_exists, background, foreground, gui)
4649
local success, hl_group = pcall(vim.api.nvim_get_hl_by_name, hl_group_name, true)
@@ -99,18 +102,16 @@ M.setup = function()
99102

100103
create_highlight_group(M.TITLE_BAR, {}, float_border_hl.foreground, nil)
101104

102-
create_highlight_group(M.GIT_ADDED, { "GitGutterAdd", "GitSignsAdd" }, nil, "5faf5f")
103-
104-
create_highlight_group(M.GIT_CONFLICT, { "GitGutterDelete", "GitSignsDelete" }, nil, "ff5900")
105-
106-
local modified = create_highlight_group(
105+
local added = create_highlight_group(M.GIT_ADDED, { "GitGutterAdd", "GitSignsAdd" }, nil, "5faf5f")
106+
create_highlight_group(M.GIT_DELETED, { "GitGutterDelete", "GitSignsDelete" }, nil, "ff5900")
107+
create_highlight_group(
107108
M.GIT_MODIFIED,
108109
{ "GitGutterChange", "GitSignsChange" },
109110
nil,
110111
"d7af5f"
111112
)
112-
113-
create_highlight_group(M.GIT_UNTRACKED, {}, nil, modified.foreground, "italic")
113+
create_highlight_group(M.GIT_CONFLICT, {}, nil, "ff8700", "italic,bold")
114+
create_highlight_group(M.GIT_UNTRACKED, {}, nil, added.foreground, "italic")
114115

115116
create_highlight_group(M.BUFFER_NUMBER, { "SpecialChar" })
116117
create_highlight_group(M.DIM_TEXT, {}, nil, "505050")

lua/neo-tree/ui/renderer.lua

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,6 @@ local remove_filtered = function(source_items, filtered_items)
8080
for _, child in ipairs(source_items) do
8181
local fby = child.filtered_by
8282
if type(fby) == "table" then
83-
log.info("filtered_by is a table", fby)
8483
if filtered_items.visible and not fby.never_show then
8584
table.insert(filtered, child)
8685
end

0 commit comments

Comments
 (0)