forked from sourcegraph/sg.nvim
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdirectory.lua
More file actions
56 lines (45 loc) · 1.35 KB
/
Copy pathdirectory.lua
File metadata and controls
56 lines (45 loc) · 1.35 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
local M = {}
local load_once = function(f)
local resolved = nil
return function(...)
if resolved == nil then
resolved = f()
end
return resolved(...)
end
end
local path_tail = function(p)
return vim.fn.fnamemodify(p, ":t")
end
local file_extension = function(p)
return vim.fn.fnamemodify(p, ":e")
end
M.transform_path = load_once(function()
local has_devicons, devicons = pcall(require, "nvim-web-devicons")
if has_devicons then
if not devicons.has_loaded() then
devicons.setup()
end
return function(filename, is_directory)
local basename = path_tail(filename)
local icon, icon_highlight
if is_directory then
-- TODO: This is a hack and only works if you have lir installed...
-- Perhaps we should just copy theirs and add our own override
icon, icon_highlight = devicons.get_icon("lir_folder_icon", basename, { default = true })
else
icon, icon_highlight = devicons.get_icon(basename, file_extension(basename), { default = false })
end
if not icon then
icon, icon_highlight = devicons.get_icon(basename, nil, { default = true })
end
local icon_display = (icon or " ") .. " " .. (filename or "")
return icon_display, icon_highlight
end
else
return function(filename)
return filename
end
end
end)
return M