Skip to content

Commit 18b0968

Browse files
committed
feat(icon): file & folder symlink icon (related to #910)
1 parent 8a0f795 commit 18b0968

File tree

2 files changed

+19
-10
lines changed

2 files changed

+19
-10
lines changed

lua/neo-tree/defaults.lua

+2
Original file line numberDiff line numberDiff line change
@@ -200,6 +200,8 @@ local config = {
200200
folder_open = "",
201201
folder_empty = "󰉖",
202202
folder_empty_open = "󰷏",
203+
folder_symlink = "",
204+
file_symlink = "",
203205
-- The next two settings are only a fallback, if you use nvim-web-devicons and configure default icons there
204206
-- then these will never be used.
205207
default = "*",

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

+17-10
Original file line numberDiff line numberDiff line change
@@ -275,7 +275,11 @@ M.icon = function(config, node, state)
275275
elseif node:is_expanded() then
276276
icon = config.folder_open or "-"
277277
else
278-
icon = config.folder_closed or "+"
278+
if node.is_link then
279+
icon = config.folder_symlink
280+
else
281+
icon = config.folder_closed or "+"
282+
end
279283
end
280284
elseif node.type == "file" or node.type == "terminal" then
281285
local success, web_devicons = pcall(require, "nvim-web-devicons")
@@ -284,6 +288,9 @@ M.icon = function(config, node, state)
284288
icon = devicon or icon
285289
highlight = hl or highlight
286290
end
291+
if node.is_link then
292+
icon = config.file_symlink
293+
end
287294
end
288295

289296
local filtered_by = M.filtered_by(config, node, state)
@@ -433,7 +440,7 @@ M.indent = function(config, node, state)
433440
return indent
434441
end
435442

436-
local get_header = function (state, label, size)
443+
local get_header = function(state, label, size)
437444
if state.sort and state.sort.label == label then
438445
local icon = state.sort.direction == 1 and "" or ""
439446
size = size - 2
@@ -442,12 +449,12 @@ local get_header = function (state, label, size)
442449
return string.format("%" .. size .. "s ", label)
443450
end
444451

445-
M.file_size = function (config, node, state)
452+
M.file_size = function(config, node, state)
446453
-- Root node gets column labels
447454
if node:get_depth() == 1 then
448455
return {
449456
text = get_header(state, "Size", 12),
450-
highlight = highlights.FILE_STATS_HEADER
457+
highlight = highlights.FILE_STATS_HEADER,
451458
}
452459
end
453460

@@ -465,7 +472,7 @@ M.file_size = function (config, node, state)
465472

466473
return {
467474
text = string.format("%12s ", text),
468-
highlight = config.highlight or highlights.FILE_STATS
475+
highlight = config.highlight or highlights.FILE_STATS,
469476
}
470477
end
471478

@@ -480,7 +487,7 @@ local file_time = function(config, node, state, stat_field)
480487
end
481488
return {
482489
text = get_header(state, label, 20),
483-
highlight = highlights.FILE_STATS_HEADER
490+
highlight = highlights.FILE_STATS_HEADER,
484491
}
485492
end
486493

@@ -490,7 +497,7 @@ local file_time = function(config, node, state, stat_field)
490497
local display = seconds and os.date("%Y-%m-%d %I:%M %p", seconds) or "-"
491498
return {
492499
text = string.format("%20s ", display),
493-
highlight = config.highlight or highlights.FILE_STATS
500+
highlight = config.highlight or highlights.FILE_STATS,
494501
}
495502
end
496503

@@ -513,19 +520,19 @@ M.symlink_target = function(config, node, state)
513520
end
514521
end
515522

516-
M.type = function (config, node, state)
523+
M.type = function(config, node, state)
517524
local text = node.ext or node.type
518525
-- Root node gets column labels
519526
if node:get_depth() == 1 then
520527
return {
521528
text = get_header(state, "Type", 10),
522-
highlight = highlights.FILE_STATS_HEADER
529+
highlight = highlights.FILE_STATS_HEADER,
523530
}
524531
end
525532

526533
return {
527534
text = string.format("%10s ", text),
528-
highlight = highlights.FILE_STATS
535+
highlight = highlights.FILE_STATS,
529536
}
530537
end
531538

0 commit comments

Comments
 (0)