-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsnacks.lua
More file actions
158 lines (151 loc) · 6.25 KB
/
Copy pathsnacks.lua
File metadata and controls
158 lines (151 loc) · 6.25 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
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
local M = {
"folke/snacks.nvim",
priority = 1000,
}
M.config = function()
-- Quick health check (all local, fast)
local checks = {
{ "node", vim.fn.executable("node") == 1 },
{ "python", vim.fn.executable("python3") == 1 or vim.fn.executable("python") == 1 },
{ "rg", vim.fn.executable("rg") == 1 },
{ "tree-sitter", vim.fn.executable("tree-sitter") == 1 },
{ "rust", vim.fn.executable("rustc") == 1 },
{ "git", vim.fn.executable("git") == 1 },
}
local health_parts = {}
for _, c in ipairs(checks) do
table.insert(health_parts, (c[2] and "✓" or "✗") .. " " .. c[1])
end
local health_line = table.concat(health_parts, " ")
-- Config git status (async fetch for accuracy, like :ConfigNews)
local config_dir = vim.fn.stdpath("config")
local git_line = "Checking for config updates…"
-- `:intro` text (version + open-source lines). The logo above is rendered as
-- separate sections so its two colors can be highlighted like vanilla.
local v = vim.version()
local header = table.concat({
"NVIM " .. string.format("v%d.%d.%d", v.major, v.minor, v.patch),
"",
"Nvim is open source and freely distributable",
"https://neovim.io/#chat",
}, "\n")
require("snacks").setup({
dashboard = {
enabled = true,
preset = { header = header },
sections = {
-- Vanilla :intro logo: first pillar = Special (pink), rest = String (green)
{ text = { { "│", hl = "Special" }, { " ╲ ││", hl = "String" } }, align = "center" },
{ text = { { "││", hl = "Special" }, { "╲╲││", hl = "String" } }, align = "center" },
{ text = { { "││", hl = "Special" }, { " ╲ │", hl = "String" } }, align = "center" },
{ padding = 1 },
{ section = "header" },
{ padding = 1 },
{ text = health_line, align = "center" },
{ text = git_line, align = "center" },
{ section = "startup" },
},
},
styles = {
snacks_image = {
relative = "editor",
col = -1,
row = 2,
},
},
-- @WARN: NEVER INCLUDE THIS. IT IS JUST SLOW
-- quickfile = {
-- enabled = true,
-- },
animate = {},
indent = {
enabled = true,
},
input = {
border = "rounded",
},
image = {
enabled = true,
doc = {
inline = false,
float = true,
},
convert = {
notify = false,
},
},
picker = {
enabled = true,
layout = {
width = 0.9,
--reverse = true,
--layout = {
-- box = "horizontal",
-- backdrop = false,
-- width = 0.9,
-- height = 0.9,
-- border = "none",
-- {
-- box = "vertical",
-- {
-- win = "list",
-- title = " Results ",
-- title_pos = "center",
-- border = "rounded"
-- },
-- {
-- win = "input",
-- height = 1,
-- border = "rounded",
-- title = "{title} {live} {flags}",
-- title_pos = "center"
-- },
-- },
-- {
-- win = "preview",
-- title = "{preview:Preview}",
-- width = 0.50,
-- border = "rounded",
-- title_pos = "center",
-- },
--},
},
},
})
-- Async fetch + behind count to update dashboard accurately
vim.system({ "git", "-C", config_dir, "fetch", "origin" }, {}, function(_)
vim.system(
{ "git", "-C", config_dir, "rev-list", "HEAD..origin/master", "--count" },
{},
vim.schedule_wrap(function(result)
local count = tonumber(result.stdout and result.stdout:gsub("%s+", "")) or 0
local new_text = count > 0 and string.format("Config is %d commit(s) behind — :ConfigNews", count)
or "Config is up to date"
for _, buf in ipairs(vim.api.nvim_list_bufs()) do
if vim.api.nvim_buf_is_valid(buf) and vim.bo[buf].filetype == "snacks_dashboard" then
local lines = vim.api.nvim_buf_get_lines(buf, 0, -1, false)
for i, line in ipairs(lines) do
if line:find("Checking for config updates") or line:find("Config is") then
local win = vim.fn.bufwinid(buf)
local width = win ~= -1 and vim.api.nvim_win_get_width(win) or vim.o.columns
local pad = math.max(0, math.floor((width - #new_text) / 2))
local padded = string.rep(" ", pad) .. new_text
vim.bo[buf].modifiable = true
vim.api.nvim_buf_set_lines(buf, i - 1, i, false, { padded })
vim.bo[buf].modifiable = false
return
end
end
end
end
end)
)
end)
-- redirect :marks and :registers to snacks picker
vim.cmd([[
cnoreabbrev <expr> marks getcmdtype() == ':' && getcmdline() == 'marks' ? 'lua require("snacks").picker.marks()' : 'marks'
cnoreabbrev <expr> registers getcmdtype() == ':' && getcmdline() == 'registers' ? 'lua require("snacks").picker.registers()' : 'registers'
cnoreabbrev <expr> reg getcmdtype() == ':' && getcmdline() == 'reg' ? 'lua require("snacks").picker.registers()' : 'reg'
]])
end
return M