Compare commits

...

15 Commits
0.0.8 ... main

Author SHA1 Message Date
LeMarsu a4cc5d9b9c feat: can declare extra lua packages 2024-06-18 01:12:08 +02:00
LeMarsu b5a3526f8a chore: bump version 2024-06-10 01:14:35 +02:00
LeMarsu 23c9863c97 feat: add option init config object to generate `init.lua` 2024-06-10 01:08:56 +02:00
LeMarsu b6630684fb feat!: `init.lua` configuration is now a `mkNeovimPkg`'s option
BREAKING CHANGE: The init configuration has moved out of runtime
configuration. It is now in the mkNeovimPkg confuguration.
2024-06-10 01:08:50 +02:00
LeMarsu 815a099805 feat: runtime is now optional
as it should be according to docs...
2024-06-10 00:36:56 +02:00
LeMarsu 3d20bc0ade chore: add alejandra to nix shell 2024-06-09 04:01:18 +02:00
LeMarsu 182c7cd83d chore: bump version 2024-06-09 02:02:47 +02:00
LeMarsu af9565fa95 feat: introduce mkPluginsFromInputs function
This permit creation of plugin before declaration of dependencies. The
biggest benefit is using those on-the-fly plugins in dependencies.
2024-06-09 00:00:56 +02:00
LeMarsu 6c499b1441 fix: plugins with init are now loaded as they should be 2024-06-08 23:57:29 +02:00
LeMarsu cbd08e5258 chore: move back to flake-utils 2024-06-08 20:03:23 +02:00
LeMarsu b36722bfe6 chore: remove sourcesWith fn, using lib.fileset 2024-06-07 20:22:01 +02:00
LeMarsu 61381e2ba0 fix: init/config are loaded to on-the-fly build plugins 2024-06-07 16:20:46 +02:00
LeMarsu da637930bc feat: add describe subcommand 2024-06-05 02:47:46 +02:00
LeMarsu c20336ee60 refactor: filters are now fully dynamic 2024-06-05 02:02:57 +02:00
LeMarsu f50f314c98 feat: Sloth command has now completion 2024-06-05 01:54:41 +02:00
18 changed files with 493 additions and 157 deletions

View File

@ -2,6 +2,40 @@
All notable changes to this project will be documented in this file.
## [0.0.10] - 2024-06-09
### Features
- Runtime is now optional
- [**breaking**] `init.lua` configuration is now a `mkNeovimPkg`'s option
- Add option init config object to generate `init.lua`
### Miscellaneous Tasks
- Add alejandra to nix shell
## [0.0.9] - 2024-06-09
### Features
- Sloth command has now completion
- Add describe subcommand
- Introduce mkPluginsFromInputs function
### Bug Fixes
- Init/config are loaded to on-the-fly build plugins
- Plugins with init are now loaded as they should be
### Refactor
- Filters are now fully dynamic
### Miscellaneous Tasks
- Remove sourcesWith fn, using lib.fileset
- Move back to flake-utils
## [0.0.8] - 2024-06-04
### Features

113
README.md
View File

@ -12,6 +12,7 @@ A [neovim] plugin and configuration management plugin, highly inspired by [lazy]
- [Usage](#usage)
- [Documentation](#documentation)
- [nix](#nix)
- [`mkPluginsFromInputs`](#mkpluginsfrominputs)
- [`mkNeovimPkg`](#mkneovimpkg)
- [neovim (lua)](#neovim-lua)
- [Using default `init.lua`](#using-default-initlua)
@ -122,34 +123,95 @@ sloth-flake.lib.mkNeovimPkg {
### nix
#### `mkPluginsFromInputs`
`mkPluginsFromInputs` is a helper function that converts flake inputs (starting by `"plugin-"` by default) into vimPlugins.
Example:
```nix
{
inputs = {
nixpkgs.url = "github:NixOS/nixpkgs/nixpkgs-unstable";
sloth-flake.url = "github:lemarsu/sloth-flake.nvim";
utils.url = "github:numtide/flake-utils";
plugin-base64 = {
url = "github:moevis/base64.nvim";
flake = false;
};
plugin-cellular-automaton = {
url = "github:eandrju/cellular-automaton.nvim";
flake = false;
};
};
outputs = {utils, sloth-flake, ...}@inputs: let
fu = utils.lib;
in fu.eachDefaultSystem (system: let
plugins = sloth-flake.lib.mkPluginsFromInputs {
inherit pkgs inputs;
};
in {
packages = rec {
default = neovim;
neovim = pkgs.callPackage ./package.nix {
# By adding `plugins` here, we can use `with plugins; base64 cellular-automaton`,
inherit plugins sloth-flake;
};
};
};
}
```
The function accepts the following attributes:
- `pkgs` **REQUIRED** the nixpkgs set.
- `inputs` **REQUIRED** the inputs from a flake.
- `predicate` **optional** predicate to filter input by name. By default, it's
filter inputs with `hasPrefix "plugin-"`.
- `nameMap` **optional** function to change the key of the input in the resulting
set. By default, the 7 first letters are removed, so to remove the "plugin-"
prefix.
- `buildVimPlugin` **optional** function used to build the plugin. Defaults to
`pkgs.vimUtils.buildVimPlugin`.
#### `mkNeovimPkg`
`mkNeovimPkg` requires only the `pkgs` argument.
Here's a list of all accepted arguments
| name | default | description |
|-------------------------|-------------------------|----------------------------------------------------------------|
| `pkgs` | N/A | The nixpkgs set. **REQUIRED** |
| `package` | `pkgs.neovim-unwrapped` | The unwrapped neovim package to use |
| `runtime` | `{}` | Your Runtime configuration (see below) |
| `dependencies` | `[]` | A list of your dependencies (see below) |
| `dependenciesExtraArgs` | `{}` | Extra arguments to load your dependencies in other files |
| `viAlias` | `false` | Wether to create a `vi` alias to run neovim |
| `vimAlias` | `false` | Wether to create a `vim` alias to run neovim |
| `vimdiffAlias` | `false` | Wether to create a `vimdiff` alias to run neovim in diff mode |
| `nvimdiffAlias` | `false` | Wether to create a `nvimdiff` alias to run neovim in diff mode |
| name | default | description |
|-------------------------|-------------------------|---------------------------------------------------------------------|
| `pkgs` | N/A | The nixpkgs set. **REQUIRED** |
| `package` | `pkgs.neovim-unwrapped` | The unwrapped neovim package to use |
| `init` | `null` | The `init.lua` of your config (string, path or init config object)¹ |
| `runtime` | `{}` | Your Runtime configuration (see below) |
| `dependencies` | `[]` | A list of your dependencies (see below) |
| `dependenciesExtraArgs` | `{}` | Extra arguments to load your dependencies in other files |
| `extraLuaPackages` | `null` | Extra lua packages needed for the plugin |
| `viAlias` | `false` | Wether to create a `vi` alias to run neovim |
| `vimAlias` | `false` | Wether to create a `vim` alias to run neovim |
| `vimdiffAlias` | `false` | Wether to create a `vimdiff` alias to run neovim in diff mode |
| `nvimdiffAlias` | `false` | Wether to create a `nvimdiff` alias to run neovim in diff mode |
> ¹ If you give your own `init.lua` as string or path, you'll have to call `sloth-flake` lua plugin yourself. See more below.
The init configuration object accepts the following properties:
| name | default | description |
|------------|---------|----------------------------------------------------------------------------|
| `init` | `null` | Lua code call before plugins init. String or path. |
| `postInit` | `null` | Lua code call after plugins init and before plugin config. String or path. |
| `config` | `null` | Luas cod call after plugins config. String or path. |
The Runtime configuration object accepts the following properties:
| name | default | description |
|-----------|---------|--------------------------------|
| `version` | `null` | The version of your runtime |
| `init` | `null` | The `init.lua` of your config¹ |
| `src` | `null` | The content of your runtime |
> ¹ If you give your own `init.lua`, you'll have to call `sloth-flake` lua plugin yourself. See more below.
The dependencies is a list of element of either:
- path: the path of the file to load other dependencies
- package: a nix package of a neovim/vim plugin
@ -157,17 +219,18 @@ The dependencies is a list of element of either:
The Plugin configuration object accepts the following properties:
| name | default | description |
|----------------|---------|----------------------------------------------------------------|
| `plugin` | N/A | The plugin to load² **REQUIRED** |
| `init` | `null` | Lua code (as string of path) to call before loading the plugin |
| `config` | `null` | Lua code (as string of path) to call after loading the plugin |
| `dependencies` | `[]` | The plugin dependencies³ |
| `lazy` | `false` | Should the plugin be loaded lazily |
| `cmd` | `[]` | Command to put as place_holder to load the lazy plugin⁴ |
| `ft` | `[]` | Filetype to watch to load the lazy plugin⁴ |
| `events` | `[]` | Events to watch to load the lazy plugin⁴⁵ |
| `keymaps` | `[]` | Keymaps that when press will load the lazy plugin⁴⁶ |
| name | default | description |
|--------------------|---------|----------------------------------------------------------------|
| `plugin` | N/A | The plugin to load² **REQUIRED** |
| `init` | `null` | Lua code (as string of path) to call before loading the plugin |
| `config` | `null` | Lua code (as string of path) to call after loading the plugin |
| `dependencies` | `[]` | The plugin dependencies³ |
| `extraLuaPackages` | `null` | Extra lua packages needed for the plugin |
| `lazy` | `false` | Should the plugin be loaded lazily |
| `cmd` | `[]` | Command to put as place_holder to load the lazy plugin⁴ |
| `ft` | `[]` | Filetype to watch to load the lazy plugin⁴ |
| `events` | `[]` | Events to watch to load the lazy plugin⁴⁵ |
| `keymaps` | `[]` | Keymaps that when press will load the lazy plugin⁴⁶ |
> ² The plugin can be either a nix package or an object with only `name` and
> `src` as properties. The latter will be used to create a nix package of your

View File

@ -1 +1 @@
0.0.8
0.0.10

View File

@ -63,24 +63,6 @@
"type": "github"
}
},
"flake-utils_2": {
"inputs": {
"systems": "systems_2"
},
"locked": {
"lastModified": 1694529238,
"narHash": "sha256-zsNZZGTGnMOf9YpHKJqMSsa0dXbfmxeoJ7xHlrt+xmY=",
"owner": "numtide",
"repo": "flake-utils",
"rev": "ff7b65b44d01cf9ba6a71320833626af21126384",
"type": "github"
},
"original": {
"owner": "numtide",
"repo": "flake-utils",
"type": "github"
}
},
"flakeCompat": {
"flake": false,
"locked": {
@ -247,20 +229,19 @@
},
"utils": {
"inputs": {
"flake-utils": "flake-utils_2"
"systems": "systems_2"
},
"locked": {
"lastModified": 1696281284,
"narHash": "sha256-xcmtTmoiiAOSk4abifbtqVZk0iwBcqJfg47iUbkwhcE=",
"owner": "gytis-ivaskevicius",
"repo": "flake-utils-plus",
"rev": "6cf1e312fb259693c4930d07ca3cbe1d07ef4a48",
"lastModified": 1710146030,
"narHash": "sha256-SZ5L6eA7HJ/nmkzGG7/ISclqe6oZdOZTNoesiInkXPQ=",
"owner": "numtide",
"repo": "flake-utils",
"rev": "b1d9ab70662946ef0850d488da1c9019f3a9752a",
"type": "github"
},
"original": {
"owner": "gytis-ivaskevicius",
"ref": "v1.4.0",
"repo": "flake-utils-plus",
"owner": "numtide",
"repo": "flake-utils",
"type": "github"
}
},

View File

@ -3,7 +3,7 @@
inputs = {
nixpkgs.url = "github:nixos/nixpkgs/nixos-unstable";
utils.url = "github:gytis-ivaskevicius/flake-utils-plus/v1.4.0";
utils.url = "github:numtide/flake-utils";
nil.url = "github:oxalica/nil";
yants.url = "github:divnix/yants";
alejandra = {
@ -20,24 +20,25 @@
yants,
...
} @ inputs: let
versionFile = builtins.replaceStrings ["\n"] [""] (builtins.readFile ./VERSION);
inherit (builtins) readFile replaceStrings;
fu = utils.lib;
versionFile = replaceStrings ["\n"] [""] (readFile ./VERSION);
version =
if self.sourceInfo ? dirtyShortRev
then "${versionFile}-${self.sourceInfo.dirtyShortRev}"
else versionFile;
version = if self.sourceInfo ? dirtyShortRev
then "${versionFile}-${self.sourceInfo.dirtyShortRev}"
else versionFile;
in
utils.lib.mkFlake {
inherit self inputs;
outputsBuilder = channel: let
system = channel.nixpkgs.system;
in {
formatter = alejandra.defaultPackage.${channel.nixpkgs.system};
devShells.default = import ./shell.nix {
pkgs = channel.nixpkgs;
inherit (inputs.nil.packages.${system}) nil;
};
forSystem = system: let
pkgs = nixpkgs.legacyPackages.${system};
formatter = alejandra.defaultPackage.${system};
inherit (inputs.nil.packages.${system}) nil;
in {
inherit formatter;
devShells.default = import ./shell.nix {
inherit pkgs nil formatter;
};
lib = import ./lib {inherit version yants;};
};
in
(fu.eachDefaultSystem forSystem)
// {lib = import ./lib {inherit version yants;};};
}

View File

@ -1,18 +1,9 @@
{version, yants}: let
{
version,
yants,
}: let
types = import ./types.nix {inherit yants;};
in {
mkNeovimPkg = import ./mkNeovimPkg.nix {inherit version types;};
sourcesWith = path: paths: let
samePath = a: let a' = builtins.toString a; in b: a' == builtins.toString b;
isRoot = samePath "/";
isInPath = path: subPath:
if isRoot subPath
then false
else (samePath path subPath) || (isInPath path (builtins.dirOf subPath));
filter = src: _type: builtins.any (includePath: isInPath includePath src) paths;
in
builtins.path {
inherit path filter;
};
mkPluginsFromInputs = import ./mkPluginsFromInputs.nix;
}

View File

@ -80,7 +80,7 @@
inherit (dep) plugin;
in
if attrNames plugin == ["name" "src"]
then {plugin = remotePluginToNeovimPlugin plugin;}
then dep // {plugin = remotePluginToNeovimPlugin plugin;}
else dep;
p = withPluginDefaults plugin;
in
@ -122,16 +122,13 @@
vimUtils.buildVimPlugin {
inherit version;
pname = "sloth-flake";
src = ../lua/sloth-flake;
src = with lib.fileset;
toSource {
root = ../.;
fileset = ../lua/sloth-flake;
};
buildPhase = ''
dir=lua/sloth-flake
mkdir -p $dir
mv *.lua $dir
for d in *; do
if [[ -d "$d" ]] && [[ "$d" != 'lua' ]]; then
mv "$d" $dir
fi
done
cat <<'LUA' > $dir/dependencies.lua
${pluginsLuaDef plugins}

View File

@ -6,21 +6,21 @@
package ? pkgs.neovim-unwrapped,
dependencies ? [],
dependenciesExtraArgs ? {},
runtime ? {},
extraLuaPackages ? (_: []),
runtime ? null,
init ? null,
viAlias ? false,
vimAlias ? false,
vimdiffAlias ? false,
nvimdiffAlias ? false,
...
} @ config: let
inherit (builtins) map;
inherit (builtins) isString isPath map;
inherit (pkgs) callPackage bash lib;
inherit (lib.strings) optionalString;
inherit (lib.lists) concatMap optional;
inherit (lib.trivial) flip;
# inherit (lib.lists) concatMap filter foldl' map optional reverseList;
# inherit (lib.attrsets) attrNames optionalAttrs;
# inherit (lib.strings) concatStringsSep fileContents hasSuffix removePrefix removeSuffix replaceStrings;
# inherit (lib.debug) traceIf traceSeq traceVal traceValSeq traceValFn;
inherit (lib.attrsets) optionalAttrs;
deps = callPackage ./deps.nix {inherit dependenciesExtraArgs types;};
@ -29,20 +29,69 @@
runtimePlugin = deps.mkRuntimePlugin runtime;
plugins =
normalizedPlugins
++ (deps.normalizePlugins [runtimePlugin sloth-flake]);
++ (
deps.normalizePlugins
([sloth-flake] ++ (optional (runtime != null) runtimePlugin))
);
extractPlugin = p: {inherit (p) optional plugin;};
extractPlugins = map extractPlugin;
customRC = let
rc = ({init ? ../lua/default_init.lua, ...}: init) runtime;
extractLuaPackageFn = plugin:
optional (plugin ? extraLuaPackages) plugin.extraLuaPackages;
extractLuaPackagesFn = plugins: let
fnList = concatMap extractLuaPackageFn plugins;
concatPackages = ps: fn: fn ps;
in
deps.textOrContent rc;
ps: concatMap (concatPackages ps) fnList;
buildInit = {
init ? null,
postInit ? null,
config ? null,
}: let
initStr = optionalString (! isNull init) ''
(function()
${deps.textOrContent init}
end)();
'';
slothCall =
if isNull postInit
then "require('sloth-flake').setup {}"
else ''
require('sloth-flake').setup {
post_init = function()
${deps.textOrContent postInit}
end,
};
'';
configStr = optionalString (! isNull config) ''
(function()
${deps.textOrContent config}
end)()
'';
in ''
-- Generated by sloth-flake
${initStr}
${slothCall}
${configStr}
'';
customRC =
if isString init || isPath init
then deps.textOrContent init
else buildInit (optionalAttrs (! isNull init) init);
neovimConfig =
pkgs.neovimUtils.makeNeovimConfig {
inherit customRC;
plugins = extractPlugins plugins;
extraLuaPackages = ps:
(extractLuaPackagesFn plugins ps) ++ (extraLuaPackages ps);
}
// {luaRcContent = customRC;};
params =

View File

@ -0,0 +1,20 @@
{
pkgs,
inputs,
predicate ? pkgs.lib.strings.hasPrefix "plugin-",
nameMap ? builtins.substring 7 (-1),
buildVimPlugin ? pkgs.vimUtils.buildVimPlugin,
}: let
inherit (builtins) attrNames filter foldl' mapAttrs;
names = filter predicate (attrNames inputs);
mkPlugin = m: k: let
name = nameMap k;
pluginDef = {
inherit name;
src = inputs.${k};
};
in
m // {${name} = pluginDef;};
plugins = foldl' mkPlugin {} names;
in
mapAttrs (_: buildVimPlugin) plugins

View File

@ -11,13 +11,20 @@ in rec {
# The version of the runtime
version = option string;
# The init configuration file
init = option (either path string);
# The content of the runtime directory
src = any;
};
neovimInitType = with yants;
struct "neovimInit" {
# Lua code to call before plugins loaded
init = option (either string path);
# Lua code called after init but before import
postInit = option (either string path);
# Lua code called after all plugins are loaded
config = option (either string path);
};
# As simple remote plugin definition
basicPluginType = with yants;
struct "basicPlugin" {
@ -65,6 +72,9 @@ in rec {
# Ensure thoses plugins are loaded before the current one
dependencies = option (list drv);
# Ensure those packages are available
extraLuaPackages = option function;
# Should this plugin be load lazily ?
lazy = option bool;
@ -98,14 +108,20 @@ in rec {
# Default is pkgs.neovim-unwrapped
package = option drv;
# init.lua configuration
init = option (eitherN [string path neovimInitType]);
# An array of dependencies.
dependencies = list dependency;
dependencies = option (list dependency);
# Extra argument to pass to dependencies files
dependenciesExtraArgs = attrs any;
dependenciesExtraArgs = option (attrs any);
# Ensure those packages are available
extraLuaPackages = option function;
# Runtime configuration
runtime = runtimeType;
runtime = option runtimeType;
# Create a vi alias
viAlias = option bool;

View File

@ -0,0 +1,74 @@
local Dep = require 'sloth-flake.dep'
local utils = require 'sloth-flake.utils'
local function yesno(value)
return value and "Yes" or "No"
end
local function list(items)
if items == nil or #items == 0 then
return "None"
end
return vim.iter(items):join(', ')
end
local function describe(dep)
utils.info('Name: %s', dep.name)
utils.info('Is loaded: %s', yesno(dep.is_loaded))
utils.info('Is lazy: %s', yesno(dep.is_lazy))
utils.info('Has init: %s', yesno(dep.init))
utils.info('Has config: %s', yesno(dep.config))
utils.info('Dependencies: %s', list(dep.dependency_names))
utils.info('Filetypes: %s', list(dep.ft))
utils.info('Commands: %s', list(dep.cmd))
if dep.events == nil then
utils.info('Events: None')
else
utils.info('Events:')
for _, event in ipairs(dep.events) do
for _, name in ipairs(event.name) do
for _, pattern in ipairs(event.pattern) do
utils.info(' - %s %s', name, pattern)
end
end
end
end
if dep.keymaps == nil then
utils.info('Keymaps: None')
else
utils.info('Keymaps:')
for _, keymap in ipairs(dep.keymaps) do
for _, mode in ipairs(keymap.mode) do
for _, mapping in ipairs(keymap.mapping) do
utils.info(' - %s %s', mode, mapping)
end
end
end
end
end
return {
complete = function(line)
if line.arg_idx == 3 then
local prefix = line.args[line.arg_idx].arg
return vim.iter(Dep.all()):map(function(name)
return name
end):filter(function(name)
return vim.startswith(name, prefix)
end):totable()
end
end,
cmd = function(plugins)
if #plugins == 0 then
utils.error("You should at least give a plugin to describe!")
return
end
local plugin = plugins[1]
local dep = Dep.get(plugin)
if dep == nil then
return utils.error([[Unknown plugin "%s"]], plugin)
end
describe(dep)
end,
}

View File

@ -6,15 +6,72 @@ local commands = {
list = require 'sloth-flake.command.list',
load = require 'sloth-flake.command.load',
version = require 'sloth-flake.command.version',
describe = require 'sloth-flake.command.describe',
}
function sloth_cmd(param)
local function parse_line(line, cursor_pos)
local raw_args = vim.split(line, ' +', { trimempty = true })
local parse_pos = 1
local args = vim.iter(raw_args):map(function(arg)
local start, stop = string.find(line, arg, parse_pos, { plain = true })
parse_pos = stop
return {
arg = arg,
start = start,
stop = stop,
}
end):totable()
parse_pos = 1
local arg_idx = 1
vim.iter(args):find(function(arg)
if cursor_pos < arg.start then
arg_idx = arg_idx - 1
return true
elseif cursor_pos <= arg.stop then
return true
end
arg_idx = arg_idx + 1
return false
end)
arg_idx = arg_idx < 1 and 1 or arg_idx
if arg_idx > #args then
args[#args + 1] = {
arg = "",
start = line:len(),
stop = line:len(),
}
end
return {
line = line,
args = args,
arg_idx = arg_idx,
pos = cursor_pos,
in_arg_pos = args[arg_idx] and cursor_pos - args[arg_idx].start + 1,
}
end
-- print(vim.inspect(parse_line('Sloth ', 6)))
local function sloth_cmd_complete(arg_lead, cmd_line, cursor_pos)
local parsed_line = parse_line(cmd_line, cursor_pos)
local arg = parsed_line.args[parsed_line.arg_idx]
if parsed_line.arg_idx == 2 then
return vim.iter(commands):map(function(name, command)
return vim.startswith(name, arg.arg) and name or nil
end):totable()
elseif parsed_line.arg_idx > 2 then
local cmd = parsed_line.args[2].arg
local command = commands[cmd]
return command and command.complete(parsed_line)
end
end
local function sloth_cmd(param)
local args = param.fargs
local cmd = args[1] or "list";
table.remove(args, 1)
local fn = commands[cmd]
if fn then
fn(args)
local command = commands[cmd]
if command then
command.cmd(args)
else
vim.api.nvim_err_writeln(string.format([[No Sloth subcommand "%s"]], cmd))
end
@ -23,6 +80,7 @@ end
function M.register()
vim.api.nvim_create_user_command('Sloth', sloth_cmd, {
nargs = '*',
complete = sloth_cmd_complete
})
end

View File

@ -1,29 +1,55 @@
local Dep = require 'sloth-flake.dep'
local utils = require 'sloth-flake.utils'
return function(args)
local filter = args[1] or "all"
local deps = vim.iter(Dep.all()):map(function(_, dep)
return dep.name
end)
if filter == "all" then
-- Nothing to do
elseif filter == "loaded" then
deps = deps:filter(function(dep)
return Dep.get(dep).is_loaded
local filters = {
all = {
filter = function(iter)
-- Nothing to do
return iter
end
},
loaded = {
filter = function(iter)
return iter:filter(function(dep)
return Dep.get(dep).is_loaded
end)
end
},
notloaded = {
filter = function(iter)
return iter:filter(function(dep)
return not Dep.get(dep).is_loaded
end)
end
},
}
return {
complete = function(line)
if line.arg_idx == 3 then
local prefix = line.args[3].arg
return vim.iter(vim.tbl_keys(filters)):filter(function(name)
return vim.startswith(name, prefix)
end):totable()
end
end,
cmd = function(args)
local filter_name = args[1] or "all"
local filter = filters[filter_name]
if not filter then
utils.error([[No Sloth list filter "%s".]], cmd)
utils.error("Filters are: %s", vim.iter(vim.tbl_keys(filters)):join(', '))
return
end
local deps = vim.iter(Dep.all()):map(function(_, dep)
return dep.name
end)
elseif filter == "notloaded" then
deps = deps:filter(function(dep)
return not Dep.get(dep).is_loaded
end)
else
utils.error([[No Sloth list filter "%s".]], cmd)
utils.error("Filters are: all, loaded, notloaded")
return
end
deps = deps:totable()
table.sort(deps)
for _, dep in ipairs(deps) do
print(string.format("- %s", dep))
end
end
deps = filter.filter(deps):totable()
table.sort(deps)
for _, dep in ipairs(deps) do
print(string.format("- %s", dep))
end
end,
}

View File

@ -1,15 +1,32 @@
local Dep = require 'sloth-flake.dep'
local utils = require 'sloth-flake.utils'
return function(plugins)
if #plugins == 0 then
utils.error("You should at least give a plugin to load!")
return
end
for _, plugin in ipairs(plugins) do
local dep = Dep.get(plugin)
if dep ~= nil then
dep:load()
return {
complete = function(line)
local previous_deps = vim.iter(line.args):enumerate():map(function(i, arg)
if i < 3 or i > line.arg_idx then return end
return arg.arg
end):totable()
local prefix = line.args[line.arg_idx].arg
return vim.iter(Dep.all()):filter(function(name, dep)
return vim.startswith(name, prefix) and not dep.is_loaded
and not vim.list_contains(previous_deps, name)
end):map(function(name)
return name
end):totable()
end,
cmd = function(plugins)
if #plugins == 0 then
utils.error("You should at least give a plugin to load!")
return
end
end
end
for _, plugin in ipairs(plugins) do
local dep = Dep.get(plugin)
if dep ~= nil then
dep:load()
end
end
end,
}

View File

@ -1,4 +1,7 @@
return function()
local version = require('sloth-flake.version')
print(string.format('Sloth v%s', version()))
end
return {
complete = function() end,
cmd = function()
local version = require('sloth-flake.version')
print(string.format('Sloth v%s', version()))
end,
}

View File

@ -33,7 +33,7 @@ function M.new(values)
dep:import()
end
if self.is_lazy then
if self.is_lazy or self.values.init then
vim.cmd("packadd " .. self.name)
end
end,

View File

@ -1,5 +1,9 @@
local M = {}
function M.info(...)
print(string.format(...))
end
function M.error(...)
vim.api.nvim_err_writeln(string.format(...))
end

View File

@ -1,13 +1,15 @@
{
pkgs,
formatter,
nil,
pkgs,
...
}:
with pkgs;
mkShell {
buildInputs = [
formatter
git-cliff
nil
sumneko-lua-language-server
git-cliff
];
}