Skip to content

Commit a101a97

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

File tree

5 files changed

+115
-14
lines changed

5 files changed

+115
-14
lines changed

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+
ignored = "○",
442+
modified = "",
443+
renamed = "🠊",
444+
staged = "",
445+
unstaged = "",
446+
unmerged = "",
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+
NeoTreeGitIgnored
458+
NeoTreeGitModified
459+
NeoTreeGitUnmerged
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

@@ -531,6 +573,7 @@ NeoTreeGitAdded File name when the git status is added.
531573
NeoTreeGitConflict File name when the git status is conflict.
532574
NeoTreeGitIgnored File name when the git status is ignored.
533575
NeoTreeGitModified File name when the git status is modified.
576+
NeoTreeGitUnmerged File name when the git status is unmerged.
534577
NeoTreeGitUntracked File name when the git status is untracked.
535578
NeoTreeHiddenByName Used for icons and names when `hide_by_name` is used.
536579
NeoTreeIndentMarker The style of indentation markers (guides). By default,

lua/neo-tree/defaults.lua

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,17 @@ local config = {
6868
use_git_status_colors = true,
6969
},
7070
git_status = {
71-
highlight = "NeoTreeDimText",
71+
symbols = {
72+
added = "",
73+
conflict = "",
74+
ignored = "",
75+
modified = "",
76+
renamed = "🠊",
77+
staged = "",
78+
unmerged = "",
79+
unstaged = "",
80+
untracked = "",
81+
}
7282
},
7383
},
7484
filesystem = {

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

Lines changed: 54 additions & 6 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,72 @@ M.git_status = function(config, node, state)
8687
end
8788
end
8889

90+
local symbols = config.symbols or {}
91+
local status
8992
local highlight = highlights.FILE_NAME
93+
local staged = symbols.unstaged
94+
local staged_hl = highlights.GIT_CONFLICT
95+
96+
if git_status:sub(2, 2) == " " then
97+
staged = symbols.staged
98+
staged_hl = highlights.GIT_ADDED
99+
end
100+
90101
if git_status:match("?$") then
102+
staged = nil
103+
status = symbols.untracked
104+
staged_hl = highlights.GIT_UNTRACKED
91105
highlight = highlights.GIT_UNTRACKED
92-
elseif git_status:match("U") then
106+
elseif git_status == "UU" then
107+
staged = symbols.unmerged
108+
staged_hl = highlights.GIT_UNMERGED
109+
status = symbols.conflict
93110
highlight = highlights.GIT_CONFLICT
94111
elseif git_status == "AA" then
112+
staged = symbols.unmerged
113+
staged_hl = highlights.GIT_UNMERGED
114+
status = symbols.conflict
115+
highlight = highlights.GIT_CONFLICT
116+
elseif git_status:match("U") then
117+
staged = symbols.unmerged
118+
staged_hl = highlights.GIT_UNMERGED
119+
status = symbols.conflict
95120
highlight = highlights.GIT_CONFLICT
96121
elseif git_status:match("M") then
122+
status = symbols.modified
97123
highlight = highlights.GIT_MODIFIED
98-
elseif git_status:match("[ACRT]") then
124+
elseif git_status:match("R") then
125+
status = symbols.renamed
126+
highlight = highlights.modified
127+
elseif git_status:match("[ACT]") then
128+
status = symbols.added
99129
highlight = highlights.GIT_ADDED
100130
elseif git_status:match("!") then
131+
staged = nil
132+
status = symbols.ignored
101133
highlight = highlights.GIT_IGNORED
102134
end
103135

104-
return {
105-
text = " [" .. git_status .. "]",
106-
highlight = config.highlight or highlight,
107-
}
136+
if status then
137+
local components = {}
138+
components[1] = {
139+
text = " " .. status,
140+
highlight = highlight,
141+
}
142+
if staged then
143+
components[2] = {
144+
text = " " .. staged,
145+
highlight = staged_hl,
146+
}
147+
end
148+
return components
149+
else
150+
return {
151+
text = " [" .. git_status .. "]",
152+
highlight = config.highlight or highlight,
153+
}
154+
end
155+
108156
end
109157

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

lua/neo-tree/ui/highlights.lua

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ M.GIT_CONFLICT = "NeoTreeGitConflict"
1717
M.GIT_IGNORED = "NeoTreeGitIgnored"
1818
M.GIT_MODIFIED = "NeoTreeGitModified"
1919
M.GIT_UNTRACKED = "NeoTreeGitUntracked"
20+
M.GIT_UNMERGED = "NeoTreeGitUnmerged"
2021
M.HIDDEN_BY_NAME = "NeoTreeHiddenByName"
2122
M.INDENT_MARKER = "NeoTreeIndentMarker"
2223
M.NORMAL = "NeoTreeNormal"
@@ -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-
105+
local added = create_highlight_group(M.GIT_ADDED, { "GitGutterAdd", "GitSignsAdd" }, nil, "5faf5f")
104106
create_highlight_group(M.GIT_CONFLICT, { "GitGutterDelete", "GitSignsDelete" }, nil, "ff5900")
105-
106-
local modified = create_highlight_group(
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_UNMERGED, {}, 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)