-
Notifications
You must be signed in to change notification settings - Fork 64
/
Copy pathincline.lua
64 lines (59 loc) · 1.62 KB
/
incline.lua
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
57
58
59
60
61
62
63
64
local M = {}
local function truncate(str, max_len)
assert(str and max_len, "string and max_len must be provided")
return vim.api.nvim_strwidth(str) > max_len and str:sub(1, max_len) .. "…" or str
end
local function render(props)
local fmt = string.format
local devicons = require "nvim-web-devicons"
local bufname = vim.api.nvim_buf_get_name(props.buf)
if bufname == "" then
return "[No name]"
end
local ret = vim.api.nvim_get_hl(0, { name = "Directory" })
local directory_color = string.format("#%06x", ret["fg"])
local parts = vim.split(vim.fn.fnamemodify(bufname, ":."), "/")
local result = {}
for idx, part in ipairs(parts) do
if next(parts, idx) then
vim.list_extend(result, {
{ truncate(part, 20) },
{ fmt(" %s ", ""), guifg = directory_color },
})
else
table.insert(result, { part, gui = "bold", guisp = directory_color })
end
end
local icon, color = devicons.get_icon_color(bufname, nil, { default = true })
table.insert(result, #result, { icon .. " ", guifg = color })
return result
end
M.config = function()
local status_ok, incl = pcall(require, "incline")
if not status_ok then
return
end
incl.setup {
window = {
zindex = 49,
winhighlight = {
inactive = {
Normal = "Directory",
},
},
width = "fit",
padding = { left = 2, right = 1 },
placement = { vertical = "top", horizontal = "right" },
margin = {
horizontal = 0,
},
},
hide = {
cursorline = false,
focused_win = true,
only_win = false,
},
render = render,
}
end
return M