mirror of
https://github.com/NotAShelf/nvf.git
synced 2026-01-02 09:05:55 +00:00
modules: explicit lib usage
This commit is contained in:
parent
9b2e2ef833
commit
caf342adb1
27 changed files with 673 additions and 684 deletions
|
|
@ -1,11 +1,15 @@
|
|||
{
|
||||
pkgs,
|
||||
config,
|
||||
lib,
|
||||
...
|
||||
}: let
|
||||
inherit (builtins) toJSON;
|
||||
inherit (lib) mkIf nvim mkLuaBinding mkMerge;
|
||||
inherit (lib.trivial) boolToString toString;
|
||||
inherit (lib.modules) mkIf mkMerge;
|
||||
inherit (lib.strings) optionalString;
|
||||
inherit (lib.lists) optionals;
|
||||
inherit (lib.nvim.binds) mkLuaBinding;
|
||||
inherit (lib.nvim.dag) entryAnywhere;
|
||||
|
||||
cfg = config.vim.assistant.copilot;
|
||||
|
||||
|
|
@ -22,69 +26,73 @@
|
|||
'';
|
||||
in {
|
||||
config = mkIf cfg.enable {
|
||||
vim.startPlugins =
|
||||
[
|
||||
"copilot-lua"
|
||||
cfg.copilotNodePackage
|
||||
]
|
||||
++ lib.optionals (cfg.cmp.enable) [
|
||||
"copilot-cmp"
|
||||
];
|
||||
vim = {
|
||||
startPlugins =
|
||||
[
|
||||
"copilot-lua"
|
||||
cfg.copilotNodePackage
|
||||
]
|
||||
++ optionals cfg.cmp.enable [
|
||||
"copilot-cmp"
|
||||
];
|
||||
|
||||
vim.luaConfigRC.copilot = nvim.dag.entryAnywhere ''
|
||||
require("copilot").setup({
|
||||
-- available options: https://github.com/zbirenbaum/copilot.lua
|
||||
copilot_node_command = "${cfg.copilotNodeCommand}",
|
||||
panel = {
|
||||
enabled = ${lib.boolToString (!cfg.cmp.enable)},
|
||||
keymap = {
|
||||
jump_prev = false,
|
||||
jump_next = false,
|
||||
accept = false,
|
||||
refresh = false,
|
||||
open = false,
|
||||
luaConfigRC.copilot = entryAnywhere ''
|
||||
require("copilot").setup({
|
||||
-- available options: https://github.com/zbirenbaum/copilot.lua
|
||||
copilot_node_command = "${cfg.copilotNodeCommand}",
|
||||
panel = {
|
||||
enabled = ${boolToString (!cfg.cmp.enable)},
|
||||
keymap = {
|
||||
jump_prev = false,
|
||||
jump_next = false,
|
||||
accept = false,
|
||||
refresh = false,
|
||||
open = false,
|
||||
},
|
||||
layout = {
|
||||
position = "${cfg.panel.position}",
|
||||
ratio = ${toString cfg.panel.ratio},
|
||||
},
|
||||
},
|
||||
layout = {
|
||||
position = "${cfg.panel.position}",
|
||||
ratio = ${toString cfg.panel.ratio},
|
||||
suggestion = {
|
||||
enabled = ${boolToString (!cfg.cmp.enable)},
|
||||
keymap = {
|
||||
accept = false,
|
||||
accept_word = false,
|
||||
accept_line = false,
|
||||
next = false,
|
||||
prev = false,
|
||||
dismiss = false,
|
||||
},
|
||||
},
|
||||
},
|
||||
suggestion = {
|
||||
enabled = ${lib.boolToString (!cfg.cmp.enable)},
|
||||
keymap = {
|
||||
accept = false,
|
||||
accept_word = false,
|
||||
accept_line = false,
|
||||
next = false,
|
||||
prev = false,
|
||||
dismiss = false,
|
||||
},
|
||||
},
|
||||
})
|
||||
})
|
||||
|
||||
${lib.optionalString (cfg.cmp.enable) ''
|
||||
require("copilot_cmp").setup()
|
||||
''}
|
||||
'';
|
||||
${optionalString cfg.cmp.enable ''
|
||||
require("copilot_cmp").setup()
|
||||
''}
|
||||
'';
|
||||
|
||||
vim.maps.normal = mkMerge [
|
||||
(mkLuaBinding cfg.mappings.panel.jumpPrev (wrapPanelBinding "require(\"copilot.panel\").jump_prev" cfg.mappings.panel.jumpPrev) "[copilot] Accept suggestion")
|
||||
(mkLuaBinding cfg.mappings.panel.jumpNext (wrapPanelBinding "require(\"copilot.panel\").jump_next" cfg.mappings.panel.jumpNext) "[copilot] Accept suggestion")
|
||||
(mkLuaBinding cfg.mappings.panel.accept (wrapPanelBinding ''require("copilot.panel").accept'' cfg.mappings.panel.accept) "[copilot] Accept suggestion")
|
||||
(mkLuaBinding cfg.mappings.panel.refresh (wrapPanelBinding "require(\"copilot.panel\").refresh" cfg.mappings.panel.refresh) "[copilot] Accept suggestion")
|
||||
(mkLuaBinding cfg.mappings.panel.open (wrapPanelBinding ''
|
||||
function() require("copilot.panel").open({ position = "${cfg.panel.position}", ratio = ${toString cfg.panel.ratio}, }) end
|
||||
''
|
||||
cfg.mappings.panel.open) "[copilot] Accept suggestion")
|
||||
];
|
||||
maps = {
|
||||
normal = mkMerge [
|
||||
(mkLuaBinding cfg.mappings.panel.jumpPrev (wrapPanelBinding "require(\"copilot.panel\").jump_prev" cfg.mappings.panel.jumpPrev) "[copilot] Accept suggestion")
|
||||
(mkLuaBinding cfg.mappings.panel.jumpNext (wrapPanelBinding "require(\"copilot.panel\").jump_next" cfg.mappings.panel.jumpNext) "[copilot] Accept suggestion")
|
||||
(mkLuaBinding cfg.mappings.panel.accept (wrapPanelBinding ''require("copilot.panel").accept'' cfg.mappings.panel.accept) "[copilot] Accept suggestion")
|
||||
(mkLuaBinding cfg.mappings.panel.refresh (wrapPanelBinding "require(\"copilot.panel\").refresh" cfg.mappings.panel.refresh) "[copilot] Accept suggestion")
|
||||
(mkLuaBinding cfg.mappings.panel.open (wrapPanelBinding ''
|
||||
function() require("copilot.panel").open({ position = "${cfg.panel.position}", ratio = ${toString cfg.panel.ratio}, }) end
|
||||
''
|
||||
cfg.mappings.panel.open) "[copilot] Accept suggestion")
|
||||
];
|
||||
|
||||
vim.maps.insert = mkMerge [
|
||||
(mkLuaBinding cfg.mappings.suggestion.accept "require(\"copilot.suggestion\").accept" "[copilot] Accept suggestion")
|
||||
(mkLuaBinding cfg.mappings.suggestion.acceptLine "require(\"copilot.suggestion\").accept_line" "[copilot] Accept suggestion (line)")
|
||||
(mkLuaBinding cfg.mappings.suggestion.acceptWord "require(\"copilot.suggestion\").accept_word" "[copilot] Accept suggestion (word)")
|
||||
(mkLuaBinding cfg.mappings.suggestion.next "require(\"copilot.suggestion\").next" "[copilot] next suggestion")
|
||||
(mkLuaBinding cfg.mappings.suggestion.prev "require(\"copilot.suggestion\").prev" "[copilot] previous suggestion")
|
||||
(mkLuaBinding cfg.mappings.suggestion.dismiss "require(\"copilot.suggestion\").dismiss" "[copilot] dismiss suggestion")
|
||||
];
|
||||
insert = mkMerge [
|
||||
(mkLuaBinding cfg.mappings.suggestion.accept "require(\"copilot.suggestion\").accept" "[copilot] Accept suggestion")
|
||||
(mkLuaBinding cfg.mappings.suggestion.acceptLine "require(\"copilot.suggestion\").accept_line" "[copilot] Accept suggestion (line)")
|
||||
(mkLuaBinding cfg.mappings.suggestion.acceptWord "require(\"copilot.suggestion\").accept_word" "[copilot] Accept suggestion (word)")
|
||||
(mkLuaBinding cfg.mappings.suggestion.next "require(\"copilot.suggestion\").next" "[copilot] next suggestion")
|
||||
(mkLuaBinding cfg.mappings.suggestion.prev "require(\"copilot.suggestion\").prev" "[copilot] previous suggestion")
|
||||
(mkLuaBinding cfg.mappings.suggestion.dismiss "require(\"copilot.suggestion\").dismiss" "[copilot] dismiss suggestion")
|
||||
];
|
||||
};
|
||||
};
|
||||
};
|
||||
}
|
||||
|
|
|
|||
|
|
@ -4,7 +4,9 @@
|
|||
lib,
|
||||
...
|
||||
}: let
|
||||
inherit (lib) mkEnableOption mkOption types;
|
||||
inherit (lib.types) enum float nullOr package str;
|
||||
inherit (lib.options) mkOption mkEnableOption;
|
||||
inherit (lib.meta) getExe;
|
||||
|
||||
cfg = config.vim.assistant.copilot;
|
||||
in {
|
||||
|
|
@ -14,7 +16,7 @@ in {
|
|||
|
||||
panel = {
|
||||
position = mkOption {
|
||||
type = types.enum [
|
||||
type = enum [
|
||||
"bottom"
|
||||
"top"
|
||||
"left"
|
||||
|
|
@ -24,7 +26,7 @@ in {
|
|||
description = "Panel position";
|
||||
};
|
||||
ratio = mkOption {
|
||||
type = types.float;
|
||||
type = float;
|
||||
default = 0.4;
|
||||
description = "Panel size";
|
||||
};
|
||||
|
|
@ -33,81 +35,81 @@ in {
|
|||
mappings = {
|
||||
panel = {
|
||||
jumpPrev = mkOption {
|
||||
type = types.nullOr types.str;
|
||||
type = nullOr str;
|
||||
default = "[[";
|
||||
description = "Jump to previous suggestion";
|
||||
};
|
||||
jumpNext = mkOption {
|
||||
type = types.nullOr types.str;
|
||||
type = nullOr str;
|
||||
default = "]]";
|
||||
description = "Jump to next suggestion";
|
||||
};
|
||||
accept = mkOption {
|
||||
type = types.nullOr types.str;
|
||||
type = nullOr str;
|
||||
default = "<CR>";
|
||||
description = "Accept suggestion";
|
||||
};
|
||||
refresh = mkOption {
|
||||
type = types.nullOr types.str;
|
||||
type = nullOr str;
|
||||
default = "gr";
|
||||
description = "Refresh suggestions";
|
||||
};
|
||||
open = mkOption {
|
||||
type = types.nullOr types.str;
|
||||
type = nullOr str;
|
||||
default = "<M-CR>";
|
||||
description = "Open suggestions";
|
||||
};
|
||||
};
|
||||
suggestion = {
|
||||
accept = mkOption {
|
||||
type = types.nullOr types.str;
|
||||
type = nullOr str;
|
||||
default = "<M-l>";
|
||||
description = "Accept suggetion";
|
||||
};
|
||||
acceptWord = mkOption {
|
||||
type = types.nullOr types.str;
|
||||
type = nullOr str;
|
||||
default = null;
|
||||
description = "Accept next word";
|
||||
};
|
||||
acceptLine = mkOption {
|
||||
type = types.nullOr types.str;
|
||||
type = nullOr str;
|
||||
default = null;
|
||||
description = "Accept next line";
|
||||
};
|
||||
prev = mkOption {
|
||||
type = types.nullOr types.str;
|
||||
type = nullOr str;
|
||||
default = "<M-[>";
|
||||
description = "Previous suggestion";
|
||||
};
|
||||
next = mkOption {
|
||||
type = types.nullOr types.str;
|
||||
type = nullOr str;
|
||||
default = "<M-]>";
|
||||
description = "Next suggestion";
|
||||
};
|
||||
dismiss = mkOption {
|
||||
type = types.nullOr types.str;
|
||||
type = nullOr str;
|
||||
default = "<C-]>";
|
||||
description = "Dismiss suggestion";
|
||||
};
|
||||
};
|
||||
};
|
||||
|
||||
copilotNodeCommand = mkOption {
|
||||
type = types.str;
|
||||
default = "${lib.getExe cfg.copilotNodePackage}";
|
||||
description = ''
|
||||
The command that will be executed to initiate nodejs for GitHub Copilot.
|
||||
Recommended to leave as default.
|
||||
'';
|
||||
};
|
||||
|
||||
copilotNodePackage = mkOption {
|
||||
type = with types; nullOr package;
|
||||
type = nullOr package;
|
||||
default = pkgs.nodejs-slim;
|
||||
description = ''
|
||||
The nodeJS package that will be used for GitHub Copilot. If you are using a custom node command
|
||||
you may want to set this option to null so that the package is not pulled from nixpkgs.
|
||||
'';
|
||||
};
|
||||
|
||||
copilotNodeCommand = mkOption {
|
||||
type = str;
|
||||
default = "${getExe cfg.copilotNodePackage}";
|
||||
description = ''
|
||||
The command that will be executed to initiate nodejs for GitHub Copilot.
|
||||
Recommended to leave as default.
|
||||
'';
|
||||
};
|
||||
};
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,6 +1,5 @@
|
|||
_: {
|
||||
{
|
||||
imports = [
|
||||
./copilot
|
||||
# ./tabnine.nix # removed until I find a way around the initialisation script the plugin requires
|
||||
];
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,54 +0,0 @@
|
|||
{
|
||||
config,
|
||||
lib,
|
||||
...
|
||||
}: let
|
||||
inherit (builtins) toJSON;
|
||||
inherit (lib) mkIf mkMerge mkExprBinding boolToString nvim;
|
||||
|
||||
cfg = config.vim.assistant.tabnine;
|
||||
in {
|
||||
config = mkIf cfg.enable {
|
||||
vim.startPlugins = ["tabnine-nvim"];
|
||||
|
||||
vim.maps.insert = mkMerge [
|
||||
(mkExprBinding cfg.mappings.accept ''
|
||||
function()
|
||||
local state = require("tabnine.state")
|
||||
local completion = require("tabnine.completion")
|
||||
|
||||
if not state.completions_cache then
|
||||
return "${toJSON cfg.mappings.accept}"
|
||||
end
|
||||
|
||||
vim.schedule(completion.accept)
|
||||
end
|
||||
'' "orzel")
|
||||
(mkExprBinding cfg.mappings.dismiss ''
|
||||
function()
|
||||
local state = require("tabnine.state")
|
||||
local completion = require("tabnine.completion")
|
||||
|
||||
if not state.completions_cache then
|
||||
return "${toJSON cfg.mappings.dismiss}"
|
||||
end
|
||||
|
||||
vim.schedule(function()
|
||||
completion.clear()
|
||||
state.completions_cache = nil
|
||||
end)
|
||||
end
|
||||
'' "orzel")
|
||||
];
|
||||
|
||||
vim.luaConfigRC.tabnine-nvim = nvim.dag.entryAnywhere ''
|
||||
require('tabnine').setup({
|
||||
disable_auto_comment = ${boolToString cfg.disable_auto_comment},
|
||||
accept_keymap = null,
|
||||
dismiss_keymap = null,
|
||||
debounce_ms = ${cfg.debounce_ms},
|
||||
exclude_filetypes = ${cfg.exclude_filetypes},
|
||||
})
|
||||
'';
|
||||
};
|
||||
}
|
||||
|
|
@ -1,6 +0,0 @@
|
|||
_: {
|
||||
imports = [
|
||||
./config.nix
|
||||
./tabnine.nix
|
||||
];
|
||||
}
|
||||
|
|
@ -1,30 +0,0 @@
|
|||
{lib, ...}: let
|
||||
inherit (lib) mkEnableOption mkOption types mkMappingOption;
|
||||
in {
|
||||
options.vim.assistant.tabnine = {
|
||||
enable = mkEnableOption "Tabnine assistant";
|
||||
|
||||
disable_auto_comment = mkOption {
|
||||
type = types.bool;
|
||||
default = true;
|
||||
description = "Disable auto comment";
|
||||
};
|
||||
|
||||
mappings = {
|
||||
accept = mkMappingOption "Accept [Tabnine]" "<Tab>";
|
||||
dismiss = mkMappingOption "Dismiss [Tabnine]" "<C-]>";
|
||||
};
|
||||
|
||||
debounce_ms = mkOption {
|
||||
type = types.int;
|
||||
default = 800;
|
||||
description = "Debounce ms";
|
||||
};
|
||||
|
||||
exclude_filetypes = mkOption {
|
||||
type = types.listOf types.str;
|
||||
default = ["TelescopePrompt" "NvimTree" "alpha"];
|
||||
description = "Exclude filetypes";
|
||||
};
|
||||
};
|
||||
}
|
||||
|
|
@ -1,4 +1,4 @@
|
|||
_: {
|
||||
{
|
||||
imports = [
|
||||
./nvim-autopairs
|
||||
];
|
||||
|
|
|
|||
|
|
@ -1,18 +1,20 @@
|
|||
{
|
||||
lib,
|
||||
config,
|
||||
lib,
|
||||
...
|
||||
}: let
|
||||
inherit (lib) mkIf nvim optionalString boolToString;
|
||||
inherit (lib.strings) optionalString;
|
||||
inherit (lib.trivial) boolToString;
|
||||
inherit (lib.modules) mkIf;
|
||||
inherit (lib.nvim.dag) entryAnywhere;
|
||||
|
||||
cfg = config.vim.autopairs;
|
||||
in {
|
||||
config =
|
||||
mkIf (cfg.enable)
|
||||
{
|
||||
vim.startPlugins = ["nvim-autopairs"];
|
||||
config = mkIf cfg.enable {
|
||||
vim = {
|
||||
startPlugins = ["nvim-autopairs"];
|
||||
|
||||
vim.luaConfigRC.autopairs = nvim.dag.entryAnywhere ''
|
||||
luaConfigRC.autopairs = entryAnywhere ''
|
||||
require("nvim-autopairs").setup{}
|
||||
${optionalString (config.vim.autocomplete.type == "nvim-compe") ''
|
||||
require('nvim-autopairs.completion.compe').setup({
|
||||
|
|
@ -23,4 +25,5 @@ in {
|
|||
''}
|
||||
'';
|
||||
};
|
||||
};
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,4 +1,4 @@
|
|||
_: {
|
||||
{
|
||||
imports = [
|
||||
./config.nix
|
||||
./nvim-autopairs.nix
|
||||
|
|
|
|||
|
|
@ -1,31 +1,37 @@
|
|||
{lib, ...}: let
|
||||
inherit (lib) mkEnableOption mkOption types;
|
||||
inherit (lib.options) mkEnableOption mkOption;
|
||||
inherit (lib.tyoes) enum bool;
|
||||
in {
|
||||
options.vim = {
|
||||
autopairs = {
|
||||
enable = mkEnableOption "autopairs" // {default = false;};
|
||||
enable = mkEnableOption "autopairs";
|
||||
|
||||
type = mkOption {
|
||||
type = types.enum ["nvim-autopairs"];
|
||||
type = enum ["nvim-autopairs"];
|
||||
default = "nvim-autopairs";
|
||||
description = "Set the autopairs type. Options: nvim-autopairs [nvim-autopairs]";
|
||||
description = ''
|
||||
Set the autopairs type.
|
||||
|
||||
Options:
|
||||
- nvim-autopairs [nvim-autopairs]
|
||||
'';
|
||||
};
|
||||
|
||||
nvim-compe = {
|
||||
map_cr = mkOption {
|
||||
type = types.bool;
|
||||
type = bool;
|
||||
default = true;
|
||||
description = ''map <CR> on insert mode'';
|
||||
};
|
||||
|
||||
map_complete = mkOption {
|
||||
type = types.bool;
|
||||
type = bool;
|
||||
default = true;
|
||||
description = "auto insert `(` after select function or method item";
|
||||
};
|
||||
|
||||
auto_select = mkOption {
|
||||
type = types.bool;
|
||||
type = bool;
|
||||
default = false;
|
||||
description = "auto select first item";
|
||||
};
|
||||
|
|
|
|||
|
|
@ -1,8 +1,9 @@
|
|||
{lib, ...}: let
|
||||
inherit (lib) mkEnableOption mkMappingOption;
|
||||
inherit (lib.options) mkEnableOption;
|
||||
inherit (lib.nvim.binds) mkMappingOption;
|
||||
in {
|
||||
options.vim.comments.comment-nvim = {
|
||||
enable = mkEnableOption "smart and powerful comment plugin for neovim comment-nvim";
|
||||
enable = mkEnableOption "smart and powerful comment plugin for neovim [comment-nvim]";
|
||||
|
||||
mappings = {
|
||||
toggleCurrentLine = mkMappingOption "Toggle current line comment" "gcc";
|
||||
|
|
|
|||
|
|
@ -1,4 +1,4 @@
|
|||
_: {
|
||||
{
|
||||
imports = [
|
||||
./comment-nvim
|
||||
];
|
||||
|
|
|
|||
|
|
@ -1,4 +1,4 @@
|
|||
_: {
|
||||
{
|
||||
imports = [
|
||||
./nvim-cmp
|
||||
];
|
||||
|
|
|
|||
|
|
@ -4,8 +4,11 @@
|
|||
...
|
||||
}: let
|
||||
inherit (builtins) toJSON;
|
||||
inherit (lib) addDescriptionsToMappings concatMapStringsSep attrNames concatStringsSep mapAttrsToList mkIf mkSetLuaBinding mkMerge optionalString;
|
||||
inherit (lib.nvim) dag;
|
||||
inherit (lib.binds) addDescriptionsToMappings mkSetLuaBinding;
|
||||
inherit (lib.strings) concatMapStringsSep concatStringsSep optionalString;
|
||||
inherit (lib.attrsets) attrNames mapAttrsToList;
|
||||
inherit (lib.modules) mkIf mkMerge;
|
||||
inherit (lib.nvim.dag) entryAfter entryAnywhere;
|
||||
|
||||
cfg = config.vim.autocomplete;
|
||||
lspkindEnabled = config.vim.lsp.enable && config.vim.lsp.lspkind.enable;
|
||||
|
|
@ -33,209 +36,213 @@
|
|||
|
||||
dagPlacement =
|
||||
if lspkindEnabled
|
||||
then dag.entryAfter ["lspkind"]
|
||||
else dag.entryAnywhere;
|
||||
then entryAfter ["lspkind"]
|
||||
else entryAnywhere;
|
||||
in {
|
||||
config = mkIf cfg.enable {
|
||||
vim.startPlugins = [
|
||||
"nvim-cmp"
|
||||
"cmp-buffer"
|
||||
"cmp-vsnip"
|
||||
"cmp-path"
|
||||
"vim-vsnip"
|
||||
];
|
||||
vim = {
|
||||
startPlugins = [
|
||||
"nvim-cmp"
|
||||
"cmp-buffer"
|
||||
"cmp-vsnip"
|
||||
"cmp-path"
|
||||
"vim-vsnip"
|
||||
];
|
||||
|
||||
vim.autocomplete.sources = {
|
||||
"nvim-cmp" = null;
|
||||
"vsnip" = "[VSnip]";
|
||||
"buffer" = "[Buffer]";
|
||||
"crates" = "[Crates]";
|
||||
"path" = "[Path]";
|
||||
"copilot" = "[Copilot]";
|
||||
autocomplete.sources = {
|
||||
"nvim-cmp" = null;
|
||||
"vsnip" = "[VSnip]";
|
||||
"buffer" = "[Buffer]";
|
||||
"crates" = "[Crates]";
|
||||
"path" = "[Path]";
|
||||
"copilot" = "[Copilot]";
|
||||
};
|
||||
|
||||
maps = {
|
||||
insert = mkMerge [
|
||||
(mkSetLuaBinding mappings.complete ''
|
||||
require('cmp').complete
|
||||
'')
|
||||
(mkSetLuaBinding mappings.confirm ''
|
||||
function()
|
||||
if not require('cmp').confirm({ select = true }) then
|
||||
local termcode = vim.api.nvim_replace_termcodes(${toJSON mappings.confirm.value}, true, false, true)
|
||||
|
||||
vim.fn.feedkeys(termcode, 'n')
|
||||
end
|
||||
end
|
||||
'')
|
||||
(mkSetLuaBinding mappings.next ''
|
||||
function()
|
||||
local has_words_before = function()
|
||||
local line, col = unpack(vim.api.nvim_win_get_cursor(0))
|
||||
return col ~= 0 and vim.api.nvim_buf_get_lines(0, line - 1, line, true)[1]:sub(col, col):match("%s") == nil
|
||||
end
|
||||
|
||||
local cmp = require('cmp')
|
||||
|
||||
local feedkey = function(key, mode)
|
||||
vim.api.nvim_feedkeys(vim.api.nvim_replace_termcodes(key, true, true, true), mode, true)
|
||||
end
|
||||
|
||||
if cmp.visible() then
|
||||
cmp.select_next_item()
|
||||
elseif vim.fn['vsnip#available'](1) == 1 then
|
||||
feedkey("<Plug>(vsnip-expand-or-jump)", "")
|
||||
elseif has_words_before() then
|
||||
cmp.complete()
|
||||
else
|
||||
local termcode = vim.api.nvim_replace_termcodes(${toJSON mappings.next.value}, true, false, true)
|
||||
|
||||
vim.fn.feedkeys(termcode, 'n')
|
||||
end
|
||||
end
|
||||
'')
|
||||
(mkSetLuaBinding mappings.previous ''
|
||||
function()
|
||||
local cmp = require('cmp')
|
||||
|
||||
local feedkey = function(key, mode)
|
||||
vim.api.nvim_feedkeys(vim.api.nvim_replace_termcodes(key, true, true, true), mode, true)
|
||||
end
|
||||
|
||||
if cmp.visible() then
|
||||
cmp.select_prev_item()
|
||||
elseif vim.fn['vsnip#available'](-1) == 1 then
|
||||
feedkeys("<Plug>(vsnip-jump-prev)", "")
|
||||
end
|
||||
end
|
||||
'')
|
||||
(mkSetLuaBinding mappings.close ''
|
||||
require('cmp').mapping.abort()
|
||||
'')
|
||||
(mkSetLuaBinding mappings.scrollDocsUp ''
|
||||
require('cmp').mapping.scroll_docs(-4)
|
||||
'')
|
||||
(mkSetLuaBinding mappings.scrollDocsDown ''
|
||||
require('cmp').mapping.scroll_docs(4)
|
||||
'')
|
||||
];
|
||||
|
||||
command = mkMerge [
|
||||
(mkSetLuaBinding mappings.complete ''
|
||||
require('cmp').complete
|
||||
'')
|
||||
(mkSetLuaBinding mappings.close ''
|
||||
require('cmp').mapping.close()
|
||||
'')
|
||||
(mkSetLuaBinding mappings.scrollDocsUp ''
|
||||
require('cmp').mapping.scroll_docs(-4)
|
||||
'')
|
||||
(mkSetLuaBinding mappings.scrollDocsDown ''
|
||||
require('cmp').mapping.scroll_docs(4)
|
||||
'')
|
||||
];
|
||||
|
||||
select = mkMerge [
|
||||
(mkSetLuaBinding mappings.next ''
|
||||
function()
|
||||
local cmp = require('cmp')
|
||||
local has_words_before = function()
|
||||
local line, col = unpack(vim.api.nvim_win_get_cursor(0))
|
||||
return col ~= 0 and vim.api.nvim_buf_get_lines(0, line - 1, line, true)[1]:sub(col, col):match("%s") == nil
|
||||
end
|
||||
|
||||
local feedkey = function(key, mode)
|
||||
vim.api.nvim_feedkeys(vim.api.nvim_replace_termcodes(key, true, true, true), mode, true)
|
||||
end
|
||||
|
||||
if cmp.visible() then
|
||||
cmp.select_next_item()
|
||||
elseif vim.fn['vsnip#available'](1) == 1 then
|
||||
feedkey("<Plug>(vsnip-expand-or-jump)", "")
|
||||
elseif has_words_before() then
|
||||
cmp.complete()
|
||||
else
|
||||
local termcode = vim.api.nvim_replace_termcodes(${toJSON mappings.next.value}, true, false, true)
|
||||
|
||||
vim.fn.feedkeys(termcode, 'n')
|
||||
end
|
||||
end
|
||||
'')
|
||||
(mkSetLuaBinding mappings.previous ''
|
||||
function()
|
||||
local cmp = require('cmp')
|
||||
|
||||
local feedkey = function(key, mode)
|
||||
vim.api.nvim_feedkeys(vim.api.nvim_replace_termcodes(key, true, true, true), mode, true)
|
||||
end
|
||||
|
||||
if cmp.visible() then
|
||||
cmp.select_prev_item()
|
||||
elseif vim.fn['vsnip#available'](-1) == 1 then
|
||||
feedkeys("<Plug>(vsnip-jump-prev)", "")
|
||||
end
|
||||
end
|
||||
'')
|
||||
];
|
||||
};
|
||||
|
||||
# TODO: alternative snippet engines to vsnip
|
||||
# https://github.com/hrsh7th/nvim-cmp/blob/main/doc/cmp.txt#L82
|
||||
luaConfigRC.completion = mkIf (cfg.type == "nvim-cmp") (dagPlacement ''
|
||||
local nvim_cmp_menu_map = function(entry, vim_item)
|
||||
-- name for each source
|
||||
vim_item.menu = ({
|
||||
${builtMaps}
|
||||
})[entry.source.name]
|
||||
print(vim_item.menu)
|
||||
return vim_item
|
||||
end
|
||||
|
||||
${optionalString lspkindEnabled ''
|
||||
lspkind_opts.before = ${cfg.formatting.format}
|
||||
''}
|
||||
|
||||
local cmp = require'cmp'
|
||||
cmp.setup({
|
||||
${optionalString config.vim.ui.borders.enable ''
|
||||
-- explicitly enabled by setting ui.borders.enable = true
|
||||
-- TODO: try to get nvim-cmp to follow global border style
|
||||
window = {
|
||||
completion = cmp.config.window.bordered(),
|
||||
documentation = cmp.config.window.bordered(),
|
||||
},
|
||||
''}
|
||||
|
||||
snippet = {
|
||||
expand = function(args)
|
||||
vim.fn["vsnip#anonymous"](args.body)
|
||||
end,
|
||||
},
|
||||
|
||||
sources = {
|
||||
${builtSources}
|
||||
},
|
||||
|
||||
completion = {
|
||||
completeopt = 'menu,menuone,noinsert',
|
||||
},
|
||||
|
||||
formatting = {
|
||||
format =
|
||||
${
|
||||
if lspkindEnabled
|
||||
then "lspkind.cmp_format(lspkind_opts)"
|
||||
else cfg.formatting.format
|
||||
},
|
||||
}
|
||||
})
|
||||
${optionalString (config.vim.autopairs.enable && config.vim.autopairs.type == "nvim-autopairs") ''
|
||||
local cmp_autopairs = require('nvim-autopairs.completion.cmp')
|
||||
cmp.event:on('confirm_done', cmp_autopairs.on_confirm_done({ map_char = { text = ""} }))
|
||||
''}
|
||||
'');
|
||||
|
||||
snippets.vsnip.enable =
|
||||
if (cfg.type == "nvim-cmp")
|
||||
then true
|
||||
else config.vim.snippets.vsnip.enable;
|
||||
};
|
||||
|
||||
vim.maps.insert = mkMerge [
|
||||
(mkSetLuaBinding mappings.complete ''
|
||||
require('cmp').complete
|
||||
'')
|
||||
(mkSetLuaBinding mappings.confirm ''
|
||||
function()
|
||||
if not require('cmp').confirm({ select = true }) then
|
||||
local termcode = vim.api.nvim_replace_termcodes(${toJSON mappings.confirm.value}, true, false, true)
|
||||
|
||||
vim.fn.feedkeys(termcode, 'n')
|
||||
end
|
||||
end
|
||||
'')
|
||||
(mkSetLuaBinding mappings.next ''
|
||||
function()
|
||||
local has_words_before = function()
|
||||
local line, col = unpack(vim.api.nvim_win_get_cursor(0))
|
||||
return col ~= 0 and vim.api.nvim_buf_get_lines(0, line - 1, line, true)[1]:sub(col, col):match("%s") == nil
|
||||
end
|
||||
|
||||
local cmp = require('cmp')
|
||||
|
||||
local feedkey = function(key, mode)
|
||||
vim.api.nvim_feedkeys(vim.api.nvim_replace_termcodes(key, true, true, true), mode, true)
|
||||
end
|
||||
|
||||
if cmp.visible() then
|
||||
cmp.select_next_item()
|
||||
elseif vim.fn['vsnip#available'](1) == 1 then
|
||||
feedkey("<Plug>(vsnip-expand-or-jump)", "")
|
||||
elseif has_words_before() then
|
||||
cmp.complete()
|
||||
else
|
||||
local termcode = vim.api.nvim_replace_termcodes(${toJSON mappings.next.value}, true, false, true)
|
||||
|
||||
vim.fn.feedkeys(termcode, 'n')
|
||||
end
|
||||
end
|
||||
'')
|
||||
(mkSetLuaBinding mappings.previous ''
|
||||
function()
|
||||
local cmp = require('cmp')
|
||||
|
||||
local feedkey = function(key, mode)
|
||||
vim.api.nvim_feedkeys(vim.api.nvim_replace_termcodes(key, true, true, true), mode, true)
|
||||
end
|
||||
|
||||
if cmp.visible() then
|
||||
cmp.select_prev_item()
|
||||
elseif vim.fn['vsnip#available'](-1) == 1 then
|
||||
feedkeys("<Plug>(vsnip-jump-prev)", "")
|
||||
end
|
||||
end
|
||||
'')
|
||||
(mkSetLuaBinding mappings.close ''
|
||||
require('cmp').mapping.abort()
|
||||
'')
|
||||
(mkSetLuaBinding mappings.scrollDocsUp ''
|
||||
require('cmp').mapping.scroll_docs(-4)
|
||||
'')
|
||||
(mkSetLuaBinding mappings.scrollDocsDown ''
|
||||
require('cmp').mapping.scroll_docs(4)
|
||||
'')
|
||||
];
|
||||
|
||||
vim.maps.command = mkMerge [
|
||||
(mkSetLuaBinding mappings.complete ''
|
||||
require('cmp').complete
|
||||
'')
|
||||
(mkSetLuaBinding mappings.close ''
|
||||
require('cmp').mapping.close()
|
||||
'')
|
||||
(mkSetLuaBinding mappings.scrollDocsUp ''
|
||||
require('cmp').mapping.scroll_docs(-4)
|
||||
'')
|
||||
(mkSetLuaBinding mappings.scrollDocsDown ''
|
||||
require('cmp').mapping.scroll_docs(4)
|
||||
'')
|
||||
];
|
||||
|
||||
vim.maps.select = mkMerge [
|
||||
(mkSetLuaBinding mappings.next ''
|
||||
function()
|
||||
local cmp = require('cmp')
|
||||
local has_words_before = function()
|
||||
local line, col = unpack(vim.api.nvim_win_get_cursor(0))
|
||||
return col ~= 0 and vim.api.nvim_buf_get_lines(0, line - 1, line, true)[1]:sub(col, col):match("%s") == nil
|
||||
end
|
||||
|
||||
local feedkey = function(key, mode)
|
||||
vim.api.nvim_feedkeys(vim.api.nvim_replace_termcodes(key, true, true, true), mode, true)
|
||||
end
|
||||
|
||||
if cmp.visible() then
|
||||
cmp.select_next_item()
|
||||
elseif vim.fn['vsnip#available'](1) == 1 then
|
||||
feedkey("<Plug>(vsnip-expand-or-jump)", "")
|
||||
elseif has_words_before() then
|
||||
cmp.complete()
|
||||
else
|
||||
local termcode = vim.api.nvim_replace_termcodes(${toJSON mappings.next.value}, true, false, true)
|
||||
|
||||
vim.fn.feedkeys(termcode, 'n')
|
||||
end
|
||||
end
|
||||
'')
|
||||
(mkSetLuaBinding mappings.previous ''
|
||||
function()
|
||||
local cmp = require('cmp')
|
||||
|
||||
local feedkey = function(key, mode)
|
||||
vim.api.nvim_feedkeys(vim.api.nvim_replace_termcodes(key, true, true, true), mode, true)
|
||||
end
|
||||
|
||||
if cmp.visible() then
|
||||
cmp.select_prev_item()
|
||||
elseif vim.fn['vsnip#available'](-1) == 1 then
|
||||
feedkeys("<Plug>(vsnip-jump-prev)", "")
|
||||
end
|
||||
end
|
||||
'')
|
||||
];
|
||||
|
||||
# TODO: alternative snippet engines to vsnip
|
||||
# https://github.com/hrsh7th/nvim-cmp/blob/main/doc/cmp.txt#L82
|
||||
vim.luaConfigRC.completion = mkIf (cfg.type == "nvim-cmp") (dagPlacement ''
|
||||
local nvim_cmp_menu_map = function(entry, vim_item)
|
||||
-- name for each source
|
||||
vim_item.menu = ({
|
||||
${builtMaps}
|
||||
})[entry.source.name]
|
||||
print(vim_item.menu)
|
||||
return vim_item
|
||||
end
|
||||
|
||||
${optionalString lspkindEnabled ''
|
||||
lspkind_opts.before = ${cfg.formatting.format}
|
||||
''}
|
||||
|
||||
local cmp = require'cmp'
|
||||
cmp.setup({
|
||||
${optionalString (config.vim.ui.borders.enable) ''
|
||||
-- explicitly enabled by setting ui.borders.enable = true
|
||||
-- TODO: try to get nvim-cmp to follow global border style
|
||||
window = {
|
||||
completion = cmp.config.window.bordered(),
|
||||
documentation = cmp.config.window.bordered(),
|
||||
},
|
||||
''}
|
||||
|
||||
snippet = {
|
||||
expand = function(args)
|
||||
vim.fn["vsnip#anonymous"](args.body)
|
||||
end,
|
||||
},
|
||||
|
||||
sources = {
|
||||
${builtSources}
|
||||
},
|
||||
|
||||
completion = {
|
||||
completeopt = 'menu,menuone,noinsert',
|
||||
},
|
||||
|
||||
formatting = {
|
||||
format =
|
||||
${
|
||||
if lspkindEnabled
|
||||
then "lspkind.cmp_format(lspkind_opts)"
|
||||
else cfg.formatting.format
|
||||
},
|
||||
}
|
||||
})
|
||||
${optionalString (config.vim.autopairs.enable && config.vim.autopairs.type == "nvim-autopairs") ''
|
||||
local cmp_autopairs = require('nvim-autopairs.completion.cmp')
|
||||
cmp.event:on('confirm_done', cmp_autopairs.on_confirm_done({ map_char = { text = ""} }))
|
||||
''}
|
||||
'');
|
||||
|
||||
vim.snippets.vsnip.enable =
|
||||
if (cfg.type == "nvim-cmp")
|
||||
then true
|
||||
else config.vim.snippets.vsnip.enable;
|
||||
};
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,4 +1,4 @@
|
|||
_: {
|
||||
{
|
||||
imports = [
|
||||
./config.nix
|
||||
./nvim-cmp.nix
|
||||
|
|
|
|||
|
|
@ -1,9 +1,10 @@
|
|||
{lib, ...}: let
|
||||
inherit (lib) mkEnableOption mkMappingOption mkOption types;
|
||||
inherit (lib.types) enum nullOr attrsOf str;
|
||||
inherit (lib) mkEnableOption mkMappingOption mkOption;
|
||||
in {
|
||||
options.vim = {
|
||||
autocomplete = {
|
||||
enable = mkEnableOption "enable autocomplete" // {default = false;};
|
||||
enable = mkEnableOption "enable autocomplete";
|
||||
|
||||
mappings = {
|
||||
complete = mkMappingOption "Complete [nvim-cmp]" "<C-Space>";
|
||||
|
|
@ -16,9 +17,14 @@ in {
|
|||
};
|
||||
|
||||
type = mkOption {
|
||||
type = types.enum ["nvim-cmp"];
|
||||
type = enum ["nvim-cmp"];
|
||||
default = "nvim-cmp";
|
||||
description = "Set the autocomplete plugin. Options: [nvim-cmp]";
|
||||
description = ''
|
||||
Set the autocomplete plugin.
|
||||
|
||||
Options:
|
||||
- [nvim-cmp]
|
||||
'';
|
||||
};
|
||||
|
||||
sources = mkOption {
|
||||
|
|
@ -31,7 +37,7 @@ in {
|
|||
|
||||
Note: only use a single attribute name per attribute set
|
||||
'';
|
||||
type = with types; attrsOf (nullOr str);
|
||||
type = attrsOf (nullOr str);
|
||||
default = {};
|
||||
example = ''
|
||||
{nvim-cmp = null; buffer = "[Buffer]";}
|
||||
|
|
@ -48,9 +54,9 @@ in {
|
|||
|
||||
Default is to call the menu mapping function.
|
||||
'';
|
||||
type = types.str;
|
||||
type = str;
|
||||
default = "nvim_cmp_menu_map";
|
||||
example = lib.literalMD ''
|
||||
example = ''
|
||||
```lua
|
||||
function(entry, vim_item)
|
||||
return vim_item
|
||||
|
|
|
|||
|
|
@ -1,11 +1,7 @@
|
|||
{
|
||||
config,
|
||||
lib,
|
||||
...
|
||||
}: let
|
||||
inherit (lib) mkEnableOption;
|
||||
{lib, ...}: let
|
||||
inherit (lib.options) mkEnableOption;
|
||||
in {
|
||||
options.vim.dashboard.alpha = {
|
||||
enable = mkEnableOption "dashboard via alpha.nvim";
|
||||
enable = mkEnableOption "dashboard [alpha-nvim]";
|
||||
};
|
||||
}
|
||||
|
|
|
|||
|
|
@ -3,217 +3,220 @@
|
|||
lib,
|
||||
...
|
||||
}: let
|
||||
inherit (lib) mkIf nvim;
|
||||
inherit (lib.options) mkIf;
|
||||
inherit (lib.nvim.dag) entryAnywhere;
|
||||
|
||||
cfg = config.vim.dashboard.alpha;
|
||||
in {
|
||||
config = mkIf cfg.enable {
|
||||
vim.startPlugins = [
|
||||
"alpha-nvim"
|
||||
"nvim-web-devicons"
|
||||
];
|
||||
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 = nvim.dag.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
|
||||
# the entire credit for this dashboard configuration to https://github.com/Rishabh672003
|
||||
# honestly, excellent work
|
||||
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 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 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 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 = {}
|
||||
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
|
||||
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 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,
|
||||
}
|
||||
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)
|
||||
--- @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 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
|
||||
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
|
||||
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 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 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 = {
|
||||
local default_header = {
|
||||
type = "text",
|
||||
val = {
|
||||
|
||||
[[███ ██ ███████ ██████ ██ ██ ██ ███ ███]],
|
||||
[[████ ██ ██ ██ ██ ██ ██ ██ ████ ████]],
|
||||
[[██ ██ ██ █████ ██ ██ ██ ██ ██ ██ ████ ██]],
|
||||
[[██ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██]],
|
||||
[[██ ████ ███████ ██████ ████ ██ ██ ██]],
|
||||
[[███ ██ ███████ ██████ ██ ██ ██ ███ ███]],
|
||||
[[████ ██ ██ ██ ██ ██ ██ ██ ████ ████]],
|
||||
[[██ ██ ██ █████ ██ ██ ██ ██ ██ ██ ████ ██]],
|
||||
[[██ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██]],
|
||||
[[██ ████ ███████ ██████ ████ ██ ██ ██]],
|
||||
|
||||
-- [[ __ ]],
|
||||
-- [[ ___ ___ ___ __ __ /\_\ ___ ___ ]],
|
||||
-- [[ / _ `\ / __`\ / __`\/\ \/\ \\/\ \ / __` __`\ ]],
|
||||
-- [[/\ \/\ \/\ __//\ \_\ \ \ \_/ |\ \ \/\ \/\ \/\ \ ]],
|
||||
-- [[\ \_\ \_\ \____\ \____/\ \___/ \ \_\ \_\ \_\ \_\]],
|
||||
-- [[ \/_/\/_/\/____/\/___/ \/__/ \/_/\/_/\/_/\/_/]],
|
||||
},
|
||||
opts = {
|
||||
position = "center",
|
||||
hl = "Type",
|
||||
-- wrap = "overflow";
|
||||
},
|
||||
}
|
||||
-- [[ __ ]],
|
||||
-- [[ ___ ___ ___ __ __ /\_\ ___ ___ ]],
|
||||
-- [[ / _ `\ / __`\ / __`\/\ \/\ \\/\ \ / __` __`\ ]],
|
||||
-- [[/\ \/\ \/\ __//\ \_\ \ \ \_/ |\ \ \/\ \/\ \/\ \ ]],
|
||||
-- [[\ \_\ \_\ \____\ \____/\ \___/ \ \_\ \_\ \_\ \_\]],
|
||||
-- [[ \/_/\/_/\/____/\/___/ \/__/ \/_/\/_/\/_/\/_/]],
|
||||
},
|
||||
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 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 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,
|
||||
},
|
||||
}
|
||||
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)
|
||||
'';
|
||||
alpha.setup(config)
|
||||
'';
|
||||
};
|
||||
};
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,4 +1,4 @@
|
|||
_: {
|
||||
{
|
||||
imports = [
|
||||
./alpha.nix
|
||||
./config.nix
|
||||
|
|
|
|||
|
|
@ -3,17 +3,20 @@
|
|||
lib,
|
||||
...
|
||||
}: let
|
||||
inherit (lib) mkIf nvim;
|
||||
inherit (lib.options) mkIf;
|
||||
inherit (lib.nvim.dag) entryAnywhere;
|
||||
|
||||
cfg = config.vim.dashboard.dashboard-nvim;
|
||||
in {
|
||||
config = mkIf cfg.enable {
|
||||
vim.startPlugins = [
|
||||
"dashboard-nvim"
|
||||
];
|
||||
vim = {
|
||||
startPlugins = [
|
||||
"dashboard-nvim"
|
||||
];
|
||||
|
||||
vim.luaConfigRC.dashboard-nvim = nvim.dag.entryAnywhere ''
|
||||
require("dashboard").setup{}
|
||||
'';
|
||||
luaConfigRC.dashboard-nvim = entryAnywhere ''
|
||||
require("dashboard").setup{}
|
||||
'';
|
||||
};
|
||||
};
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,4 +1,4 @@
|
|||
{...}: {
|
||||
{
|
||||
imports = [
|
||||
./alpha
|
||||
./dashboard-nvim
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue