treewide: begin restructuring the module tree

This commit is contained in:
raf 2024-04-07 17:16:08 +03:00
commit 7c730a78e5
No known key found for this signature in database
GPG key ID: 02D1DD3FA08B6B29
254 changed files with 749 additions and 664 deletions

View file

@ -0,0 +1,7 @@
{lib, ...}: let
inherit (lib.options) mkEnableOption;
in {
options.vim.dashboard.alpha = {
enable = mkEnableOption "fast and fully programmable greeter for neovim [alpha.mvim]";
};
}

View file

@ -0,0 +1,220 @@
{
config,
lib,
...
}: let
inherit (lib.modules) mkIf;
inherit (lib.nvim.dag) entryAnywhere;
cfg = config.vim.dashboard.alpha;
in {
config = mkIf cfg.enable {
vim.startPlugins = [
"alpha-nvim"
"nvim-web-devicons"
];
# the entire credit for this dashboard configuration to https://github.com/Rishabh672003
# honestly, excellent work
vim.luaConfigRC.alpha = entryAnywhere ''
local alpha = require("alpha")
local plenary_path = require("plenary.path")
local dashboard = require("alpha.themes.dashboard")
local cdir = vim.fn.getcwd()
local if_nil = vim.F.if_nil
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)
'';
};
}

View file

@ -0,0 +1,6 @@
{
imports = [
./alpha.nix
./config.nix
];
}

View file

@ -0,0 +1,20 @@
{
config,
lib,
...
}: let
inherit (lib.modules) mkIf;
inherit (lib.nvim.dag) entryAnywhere;
cfg = config.vim.dashboard.dashboard-nvim;
in {
config = mkIf cfg.enable {
vim.startPlugins = [
"dashboard-nvim"
];
vim.luaConfigRC.dashboard-nvim = entryAnywhere ''
require("dashboard").setup{}
'';
};
}

View file

@ -0,0 +1,7 @@
{lib, ...}: let
inherit (lib.options) mkEnableOption;
in {
options.vim.dashboard.dashboard-nvim = {
enable = mkEnableOption "Fancy and Blazing Fast start screen plugin of neovim [dashboard.nvim]";
};
}

View file

@ -0,0 +1,6 @@
{
imports = [
./dashboard-nvim.nix
./config.nix
];
}

View file

@ -0,0 +1,7 @@
{
imports = [
./alpha
./dashboard-nvim
./startify
];
}

View file

@ -0,0 +1,50 @@
{
pkgs,
config,
lib,
...
}: let
inherit (lib.modules) mkIf;
inherit (lib.nvim.vim) mkVimBool;
cfg = config.vim.dashboard.startify;
in {
config = mkIf cfg.enable {
vim.startPlugins = with pkgs.vimPlugins; [vim-startify];
vim.globals = {
"startify_custom_header" =
if cfg.customHeader == []
then null
else cfg.customHeader;
"startify_custom_footer" =
if cfg.customFooter == []
then null
else cfg.customFooter;
"startify_bookmarks" = cfg.bookmarks;
"startify_lists" = cfg.lists;
"startify_change_to_dir" = mkVimBool cfg.changeToDir;
"startify_change_to_vcs_root" = mkVimBool cfg.changeToVCRoot;
"startify_change_cmd" = cfg.changeDirCmd;
"startify_skiplist" = cfg.skipList;
"startify_update_oldfiles" = mkVimBool cfg.updateOldFiles;
"startify_session_autoload" = mkVimBool cfg.sessionAutoload;
"startify_commands" = cfg.commands;
"startify_files_number" = cfg.filesNumber;
"startify_custom_indices" = cfg.customIndices;
"startify_disable_at_vimenter" = mkVimBool cfg.disableOnStartup;
"startify_enable_unsafe" = mkVimBool cfg.unsafe;
"startify_padding_left" = cfg.paddingLeft;
"startify_use_env" = mkVimBool cfg.useEnv;
"startify_session_before_save" = cfg.sessionBeforeSave;
"startify_session_persistence" = mkVimBool cfg.sessionPersistence;
"startify_session_delete_buffers" = mkVimBool cfg.sessionDeleteBuffers;
"startify_session_dir" = cfg.sessionDir;
"startify_skiplist_server" = cfg.skipListServer;
"startify_session_remove_lines" = cfg.sessionRemoveLines;
"startify_session_savevars" = cfg.sessionSavevars;
"startify_session_savecmds" = cfg.sessionSavecmds;
"startify_session_sort" = mkVimBool cfg.sessionSort;
};
};
}

View file

@ -0,0 +1,6 @@
_: {
imports = [
./startify.nix
./config.nix
];
}

View file

@ -0,0 +1,190 @@
{
config,
lib,
...
}: let
inherit (lib.options) mkEnableOption mkOption;
inherit (lib.types) listOf attrs bool enum str oneOf int;
in {
options.vim.dashboard.startify = {
enable = mkEnableOption "dashboard via vim-startify";
bookmarks = mkOption {
default = [];
description = ''List of book marks to disaply on start page'';
type = listOf attrs;
example = {"c" = "~/.vimrc";};
};
changeToDir = mkOption {
default = true;
description = "Should vim change to the directory of the file you open";
type = bool;
};
changeToVCRoot = mkOption {
default = false;
description = "Should vim change to the version control root when opening a file";
type = bool;
};
changeDirCmd = mkOption {
default = "lcd";
description = "Command to change the current window with. Can be cd, lcd or tcd";
type = enum ["cd" "lcd" "tcd"];
};
customHeader = mkOption {
default = [];
description = "Text to place in the header";
type = listOf str;
};
customFooter = mkOption {
default = [];
description = "Text to place in the footer";
type = listOf str;
};
lists = mkOption {
default = [
{
type = "files";
header = ["MRU"];
}
{
type = "dir";
header = ["MRU Current Directory"];
}
{
type = "sessions";
header = ["Sessions"];
}
{
type = "bookmarks";
header = ["Bookmarks"];
}
{
type = "commands";
header = ["Commands"];
}
];
description = "Specify the lists and in what order they are displayed on startify.";
type = listOf attrs;
};
skipList = mkOption {
default = [];
description = "List of regex patterns to exclude from MRU lists";
type = listOf str;
};
updateOldFiles = mkOption {
default = false;
description = "Set if you want startify to always update and not just when neovim closes";
type = bool;
};
sessionAutoload = mkOption {
default = false;
description = "Make startify auto load Session.vim files from the current directory";
type = bool;
};
commands = mkOption {
default = [];
description = "Commands that are presented to the user on startify page";
type = listOf (oneOf [str attrs (listOf str)]);
};
filesNumber = mkOption {
default = 10;
description = "How many files to list";
type = int;
};
customIndices = mkOption {
default = [];
description = "Specify a list of default charecters to use instead of numbers";
type = listOf str;
};
disableOnStartup = mkOption {
default = false;
description = "Prevent startify from opening on startup but can be called with :Startify";
type = bool;
};
unsafe = mkOption {
default = false;
description = "Turns on unsafe mode for Startify. Stops resolving links, checking files are readable and filtering bookmark list";
type = bool;
};
paddingLeft = mkOption {
default = 3;
description = "Number of spaces used for left padding.";
type = int;
};
useEnv = mkOption {
default = false;
description = "Show environment variables in path if name is shorter than value";
type = bool;
};
sessionBeforeSave = mkOption {
default = [];
description = "Commands to run before saving a session";
type = listOf str;
};
sessionPersistence = mkOption {
default = false;
description = "Persist session before leaving vim or switching session";
type = bool;
};
sessionDeleteBuffers = mkOption {
default = true;
description = "Delete all buffers when loading or closing a session";
type = bool;
};
sessionDir = mkOption {
default = "~/.vim/session";
description = "Directory to save and load sessions from";
type = str;
};
skipListServer = mkOption {
default = [];
description = "List of vim servers to not load startify for";
type = listOf str;
};
sessionRemoveLines = mkOption {
default = [];
description = "Patterns to remove from session files";
type = listOf str;
};
sessionSavevars = mkOption {
default = [];
description = "List of variables to save into a session file.";
type = listOf str;
};
sessionSavecmds = mkOption {
default = [];
description = "List of commands to run when loading a session.";
type = listOf str;
};
sessionSort = mkOption {
default = false;
description = "Set if you want items sorted by date rather than alphabetically";
type = bool;
};
};
}