mirror of
https://github.com/NotAShelf/nvf.git
synced 2025-04-02 03:01:54 +00:00
dashboard/alpha: configure with nix (#699)
Co-authored-by: raf <me@notashelf.dev>
This commit is contained in:
parent
dd281b78e5
commit
3c52dbfd72
4 changed files with 52 additions and 204 deletions
2
.github/typos.toml
vendored
2
.github/typos.toml
vendored
|
@ -1,5 +1,5 @@
|
||||||
|
|
||||||
default.extend-ignore-words-re = ["(?i)(noice)", "befores", "annote", "viw"]
|
default.extend-ignore-words-re = ["(?i)(noice)", "befores", "annote", "viw", "BANanaD3V"]
|
||||||
files.extend-exclude = [
|
files.extend-exclude = [
|
||||||
"npins/sources.json"
|
"npins/sources.json"
|
||||||
]
|
]
|
||||||
|
|
|
@ -5,6 +5,8 @@
|
||||||
- `git-conflict` keybinds are now prefixed with `<leader>` to avoid conflicting
|
- `git-conflict` keybinds are now prefixed with `<leader>` to avoid conflicting
|
||||||
with builtins.
|
with builtins.
|
||||||
|
|
||||||
|
- `alpha` is now configured with nix, default config removed.
|
||||||
|
|
||||||
[NotAShelf](https://github.com/notashelf):
|
[NotAShelf](https://github.com/notashelf):
|
||||||
|
|
||||||
[typst-preview.nvim]: https://github.com/chomosuke/typst-preview.nvim
|
[typst-preview.nvim]: https://github.com/chomosuke/typst-preview.nvim
|
||||||
|
@ -235,3 +237,7 @@
|
||||||
[projekt0n/github-nvim-theme]: https://github.com/projekt0n/github-nvim-theme
|
[projekt0n/github-nvim-theme]: https://github.com/projekt0n/github-nvim-theme
|
||||||
|
|
||||||
- Add `github-nvim-theme` theme from [projekt0n/github-nvim-theme].
|
- Add `github-nvim-theme` theme from [projekt0n/github-nvim-theme].
|
||||||
|
|
||||||
|
[BANanaD3V](https://github.com/BANanaD3V):
|
||||||
|
|
||||||
|
- `alpha` is now configured with nix.
|
||||||
|
|
|
@ -1,7 +1,23 @@
|
||||||
{lib, ...}: let
|
{lib, ...}: let
|
||||||
inherit (lib.options) mkEnableOption;
|
inherit (lib.options) mkEnableOption mkOption;
|
||||||
|
inherit (lib.types) listOf attrsOf anything nullOr enum;
|
||||||
in {
|
in {
|
||||||
options.vim.dashboard.alpha = {
|
options.vim.dashboard.alpha = {
|
||||||
enable = mkEnableOption "fast and fully programmable greeter for neovim [alpha.mvim]";
|
enable = mkEnableOption "fast and fully programmable greeter for neovim [alpha.nvim]";
|
||||||
|
theme = mkOption {
|
||||||
|
type = nullOr (enum ["dashboard" "startify" "theta"]);
|
||||||
|
default = "dashboard";
|
||||||
|
description = "Alpha default theme to use";
|
||||||
|
};
|
||||||
|
layout = mkOption {
|
||||||
|
type = listOf (attrsOf anything);
|
||||||
|
default = [];
|
||||||
|
description = "Alpha dashboard layout";
|
||||||
|
};
|
||||||
|
opts = mkOption {
|
||||||
|
type = attrsOf anything;
|
||||||
|
default = {};
|
||||||
|
description = "Optional global options";
|
||||||
|
};
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
|
@ -5,8 +5,11 @@
|
||||||
}: let
|
}: let
|
||||||
inherit (lib.modules) mkIf;
|
inherit (lib.modules) mkIf;
|
||||||
inherit (lib.nvim.dag) entryAnywhere;
|
inherit (lib.nvim.dag) entryAnywhere;
|
||||||
|
inherit (lib.nvim.lua) toLuaObject;
|
||||||
|
|
||||||
cfg = config.vim.dashboard.alpha;
|
cfg = config.vim.dashboard.alpha;
|
||||||
|
themeDefined = cfg.theme != null;
|
||||||
|
layoutDefined = cfg.layout != [];
|
||||||
in {
|
in {
|
||||||
config = mkIf cfg.enable {
|
config = mkIf cfg.enable {
|
||||||
vim.startPlugins = [
|
vim.startPlugins = [
|
||||||
|
@ -14,207 +17,30 @@ in {
|
||||||
"nvim-web-devicons"
|
"nvim-web-devicons"
|
||||||
];
|
];
|
||||||
|
|
||||||
# the entire credit for this dashboard configuration to https://github.com/Rishabh672003
|
vim.pluginRC.alpha = let
|
||||||
# honestly, excellent work
|
setupOpts =
|
||||||
vim.pluginRC.alpha = entryAnywhere ''
|
if themeDefined
|
||||||
local alpha = require("alpha")
|
then lib.generators.mkLuaInline "require'alpha.themes.${cfg.theme}'.config"
|
||||||
local plenary_path = require("plenary.path")
|
else {
|
||||||
local dashboard = require("alpha.themes.dashboard")
|
inherit (cfg) layout opts;
|
||||||
local cdir = vim.fn.getcwd()
|
};
|
||||||
local if_nil = vim.F.if_nil
|
in ''
|
||||||
|
require('alpha').setup(${toLuaObject setupOpts})
|
||||||
local nvim_web_devicons = {
|
|
||||||
enabled = true,
|
|
||||||
highlight = true,
|
|
||||||
}
|
|
||||||
|
|
||||||
local function get_extension(fn)
|
|
||||||
local match = fn:match("^.+(%..+)$")
|
|
||||||
local ext = ""
|
|
||||||
if match ~= nil then
|
|
||||||
ext = match:sub(2)
|
|
||||||
end
|
|
||||||
return ext
|
|
||||||
end
|
|
||||||
|
|
||||||
local function icon(fn)
|
|
||||||
local nwd = require("nvim-web-devicons")
|
|
||||||
local ext = get_extension(fn)
|
|
||||||
return nwd.get_icon(fn, ext, { default = true })
|
|
||||||
end
|
|
||||||
|
|
||||||
local function file_button(fn, sc, short_fn)
|
|
||||||
short_fn = short_fn or fn
|
|
||||||
local ico_txt
|
|
||||||
local fb_hl = {}
|
|
||||||
|
|
||||||
if nvim_web_devicons.enabled then
|
|
||||||
local ico, hl = icon(fn)
|
|
||||||
local hl_option_type = type(nvim_web_devicons.highlight)
|
|
||||||
if hl_option_type == "boolean" then
|
|
||||||
if hl and nvim_web_devicons.highlight then
|
|
||||||
table.insert(fb_hl, { hl, 0, 3 })
|
|
||||||
end
|
|
||||||
end
|
|
||||||
if hl_option_type == "string" then
|
|
||||||
table.insert(fb_hl, { nvim_web_devicons.highlight, 0, 3 })
|
|
||||||
end
|
|
||||||
ico_txt = ico .. " "
|
|
||||||
else
|
|
||||||
ico_txt = ""
|
|
||||||
end
|
|
||||||
local file_button_el = dashboard.button(sc, ico_txt .. short_fn, "<cmd>e " .. fn .. " <CR>")
|
|
||||||
local fn_start = short_fn:match(".*[/\\]")
|
|
||||||
if fn_start ~= nil then
|
|
||||||
table.insert(fb_hl, { "Comment", #ico_txt - 2, #fn_start + #ico_txt })
|
|
||||||
end
|
|
||||||
file_button_el.opts.hl = fb_hl
|
|
||||||
return file_button_el
|
|
||||||
end
|
|
||||||
|
|
||||||
local default_mru_ignore = { "gitcommit" }
|
|
||||||
|
|
||||||
local mru_opts = {
|
|
||||||
ignore = function(path, ext)
|
|
||||||
return (string.find(path, "COMMIT_EDITMSG")) or (vim.tbl_contains(default_mru_ignore, ext))
|
|
||||||
end,
|
|
||||||
}
|
|
||||||
|
|
||||||
--- @param start number
|
|
||||||
--- @param cwd string optional
|
|
||||||
--- @param items_number number optional number of items to generate, default = 10
|
|
||||||
local function mru(start, cwd, items_number, opts)
|
|
||||||
opts = opts or mru_opts
|
|
||||||
items_number = if_nil(items_number, 15)
|
|
||||||
|
|
||||||
local oldfiles = {}
|
|
||||||
for _, v in pairs(vim.v.oldfiles) do
|
|
||||||
if #oldfiles == items_number then
|
|
||||||
break
|
|
||||||
end
|
|
||||||
local cwd_cond
|
|
||||||
if not cwd then
|
|
||||||
cwd_cond = true
|
|
||||||
else
|
|
||||||
cwd_cond = vim.startswith(v, cwd)
|
|
||||||
end
|
|
||||||
local ignore = (opts.ignore and opts.ignore(v, get_extension(v))) or false
|
|
||||||
if (vim.fn.filereadable(v) == 1) and cwd_cond and not ignore then
|
|
||||||
oldfiles[#oldfiles + 1] = v
|
|
||||||
end
|
|
||||||
end
|
|
||||||
local target_width = 35
|
|
||||||
|
|
||||||
local tbl = {}
|
|
||||||
for i, fn in ipairs(oldfiles) do
|
|
||||||
local short_fn
|
|
||||||
if cwd then
|
|
||||||
short_fn = vim.fn.fnamemodify(fn, ":.")
|
|
||||||
else
|
|
||||||
short_fn = vim.fn.fnamemodify(fn, ":~")
|
|
||||||
end
|
|
||||||
|
|
||||||
if #short_fn > target_width then
|
|
||||||
short_fn = plenary_path.new(short_fn):shorten(1, { -2, -1 })
|
|
||||||
if #short_fn > target_width then
|
|
||||||
short_fn = plenary_path.new(short_fn):shorten(1, { -1 })
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
local shortcut = tostring(i + start - 1)
|
|
||||||
|
|
||||||
local file_button_el = file_button(fn, shortcut, short_fn)
|
|
||||||
tbl[i] = file_button_el
|
|
||||||
end
|
|
||||||
return {
|
|
||||||
type = "group",
|
|
||||||
val = tbl,
|
|
||||||
opts = {},
|
|
||||||
}
|
|
||||||
end
|
|
||||||
|
|
||||||
local default_header = {
|
|
||||||
type = "text",
|
|
||||||
val = {
|
|
||||||
|
|
||||||
[[███ ██ ███████ ██████ ██ ██ ██ ███ ███]],
|
|
||||||
[[████ ██ ██ ██ ██ ██ ██ ██ ████ ████]],
|
|
||||||
[[██ ██ ██ █████ ██ ██ ██ ██ ██ ██ ████ ██]],
|
|
||||||
[[██ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██]],
|
|
||||||
[[██ ████ ███████ ██████ ████ ██ ██ ██]],
|
|
||||||
|
|
||||||
-- [[ __ ]],
|
|
||||||
-- [[ ___ ___ ___ __ __ /\_\ ___ ___ ]],
|
|
||||||
-- [[ / _ `\ / __`\ / __`\/\ \/\ \\/\ \ / __` __`\ ]],
|
|
||||||
-- [[/\ \/\ \/\ __//\ \_\ \ \ \_/ |\ \ \/\ \/\ \/\ \ ]],
|
|
||||||
-- [[\ \_\ \_\ \____\ \____/\ \___/ \ \_\ \_\ \_\ \_\]],
|
|
||||||
-- [[ \/_/\/_/\/____/\/___/ \/__/ \/_/\/_/\/_/\/_/]],
|
|
||||||
},
|
|
||||||
opts = {
|
|
||||||
position = "center",
|
|
||||||
hl = "Type",
|
|
||||||
-- wrap = "overflow";
|
|
||||||
},
|
|
||||||
}
|
|
||||||
|
|
||||||
local section_mru = {
|
|
||||||
type = "group",
|
|
||||||
val = {
|
|
||||||
{
|
|
||||||
type = "text",
|
|
||||||
val = "Recent files",
|
|
||||||
opts = {
|
|
||||||
hl = "SpecialComment",
|
|
||||||
shrink_margin = false,
|
|
||||||
position = "center",
|
|
||||||
},
|
|
||||||
},
|
|
||||||
{ type = "padding", val = 1 },
|
|
||||||
{
|
|
||||||
type = "group",
|
|
||||||
val = function()
|
|
||||||
return { mru(0, cdir) }
|
|
||||||
end,
|
|
||||||
opts = { shrink_margin = false },
|
|
||||||
},
|
|
||||||
},
|
|
||||||
}
|
|
||||||
|
|
||||||
local buttons = {
|
|
||||||
type = "group",
|
|
||||||
val = {
|
|
||||||
{ type = "text", val = "Quick links", opts = { hl = "SpecialComment", position = "center" } },
|
|
||||||
{ type = "padding", val = 1 },
|
|
||||||
-- TODO: buttons should be added based on whether or not the relevant plugin is available
|
|
||||||
dashboard.button("e", " New file", "<cmd>ene<CR>"), -- available all the time
|
|
||||||
dashboard.button("SPC F", " Find file"), -- telescope
|
|
||||||
dashboard.button("SPC ff", " Live grep"), -- telescope
|
|
||||||
dashboard.button("SPC p", " Projects"), -- any project
|
|
||||||
dashboard.button("q", " Quit", "<cmd>qa<CR>"), -- available all the time
|
|
||||||
},
|
|
||||||
position = "center",
|
|
||||||
}
|
|
||||||
|
|
||||||
local config = {
|
|
||||||
layout = {
|
|
||||||
{ type = "padding", val = 2 },
|
|
||||||
default_header,
|
|
||||||
{ type = "padding", val = 2 },
|
|
||||||
section_mru,
|
|
||||||
{ type = "padding", val = 2 },
|
|
||||||
buttons,
|
|
||||||
},
|
|
||||||
opts = {
|
|
||||||
margin = 5,
|
|
||||||
setup = function()
|
|
||||||
vim.cmd([[
|
|
||||||
autocmd alpha_temp DirChanged * lua require('alpha').redraw()
|
|
||||||
]])
|
|
||||||
end,
|
|
||||||
},
|
|
||||||
}
|
|
||||||
|
|
||||||
alpha.setup(config)
|
|
||||||
'';
|
'';
|
||||||
|
|
||||||
|
assertions = [
|
||||||
|
{
|
||||||
|
assertion = themeDefined || layoutDefined;
|
||||||
|
message = ''
|
||||||
|
One of 'theme' or 'layout' should be defined in Alpha configuration.
|
||||||
|
'';
|
||||||
|
}
|
||||||
|
{
|
||||||
|
assertion = !(themeDefined && layoutDefined);
|
||||||
|
message = ''
|
||||||
|
'theme' and 'layout' cannot be defined at the same time.
|
||||||
|
'';
|
||||||
|
}
|
||||||
|
];
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Reference in a new issue