refactor(nvim): Change snacks/dashboard.nix to also host the extraConfig

This commit is contained in:
demenik
2025-12-17 12:28:31 +01:00
parent a0775faedd
commit 210ce6236c
2 changed files with 78 additions and 75 deletions

View File

@@ -1,53 +1,83 @@
let {
themes = import ./themes.nix; plugins.snacks.dashboard = let
theme = themes.dg_baby; themes = import ./themes.nix;
in { theme = themes.dg_baby;
enabled = true; in {
preset = { enabled = true;
inherit (theme) header; preset = {
keys = [ inherit (theme) header;
keys = [
{
icon = " ";
key = "f";
desc = "Find File";
action = ":lua Snacks.dashboard.pick('files')";
}
{
icon = " ";
key = "n";
desc = "New File";
action = ":ene | startinsert";
}
{
icon = " ";
key = "l";
desc = "Live Grep";
action = ":lua Snacks.dashboard.pick('live_grep')";
}
{
icon = " ";
key = "o";
desc = "Old Files";
action = ":lua Snacks.dashboard.pick('oldfiles')";
}
{
icon = " ";
key = "q";
desc = "Quit";
action = ":qa";
}
];
};
sections = [
{section = "header";}
{ {
icon = " "; section = "keys";
key = "f"; gap = 1;
desc = "Find File"; padding = 1;
action = ":lua Snacks.dashboard.pick('files')";
} }
{ {
icon = " "; title = theme.quote;
key = "n"; align = "center";
desc = "New File";
action = ":ene | startinsert";
}
{
icon = " ";
key = "l";
desc = "Live Grep";
action = ":lua Snacks.dashboard.pick('live_grep')";
}
{
icon = " ";
key = "o";
desc = "Old Files";
action = ":lua Snacks.dashboard.pick('oldfiles')";
}
{
icon = " ";
key = "q";
desc = "Quit";
action = ":qa";
} }
]; ];
}; };
sections = [
{section = "header";} extraConfigLua =
{ # lua
section = "keys"; ''
gap = 1; local prev = { new_name = "", old_name = "" } -- Prevents duplicate events
padding = 1; vim.api.nvim_create_autocmd("User", {
} pattern = "NvimTreeSetup",
{ callback = function()
title = theme.quote; local events = require("nvim-tree.api").events
align = "center"; events.subscribe(events.Event.NodeRenamed, function(data)
} if prev.new_name ~= data.new_name or prev.old_name ~= data.old_name then
]; data = data
Snacks.rename.on_rename_file(data.old_name, data.new_name)
end
end)
end,
})
vim.api.nvim_create_autocmd("User", {
pattern = "SnacksDashboardOpened",
callback = function()
if vim.bo.filetype == "snacks_dashboard" then
vim.b.minitrailspace_disable = true
vim.b.miniindentscope_disable = true
end
end,
})
'';
} }

View File

@@ -1,4 +1,6 @@
{ {
imports = [./dashboard.nix];
plugins.snacks = { plugins.snacks = {
enable = true; enable = true;
settings = { settings = {
@@ -11,35 +13,6 @@
image.enabled = true; image.enabled = true;
quickfile.enabled = true; quickfile.enabled = true;
rename.enabled = true; rename.enabled = true;
dashboard = import ./dashboard.nix;
}; };
}; };
extraConfigLua =
# lua
''
local prev = { new_name = "", old_name = "" } -- Prevents duplicate events
vim.api.nvim_create_autocmd("User", {
pattern = "NvimTreeSetup",
callback = function()
local events = require("nvim-tree.api").events
events.subscribe(events.Event.NodeRenamed, function(data)
if prev.new_name ~= data.new_name or prev.old_name ~= data.old_name then
data = data
Snacks.rename.on_rename_file(data.old_name, data.new_name)
end
end)
end,
})
vim.api.nvim_create_autocmd("User", {
pattern = "SnacksDashboardOpened",
callback = function()
if vim.bo.filetype == "snacks_dashboard" then
vim.b.minitrailspace_disable = true
vim.b.miniindentscope_disable = true
end
end,
})
'';
} }