diff --git a/lib/deps.nix b/lib/deps.nix index 05b8a2f..4633c55 100644 --- a/lib/deps.nix +++ b/lib/deps.nix @@ -81,7 +81,12 @@ buildPhase = '' dir=lua/sloth-flake mkdir -p $dir - mv *.lua $dir + cp *.lua $dir + for d in *; do + if [[ -d "$d" ]] && [[ "$d" != 'lua' ]]; then + cp -r "$d" $dir + fi + done cat <<'LUA' > $dir/dependencies.lua ${pluginsLuaDef plugins} diff --git a/lua/sloth-flake/command.lua b/lua/sloth-flake/command.lua deleted file mode 100644 index ac0c7b0..0000000 --- a/lua/sloth-flake/command.lua +++ /dev/null @@ -1,74 +0,0 @@ -local Dep = require 'sloth-flake.dep' - -local M = {} - -local function vim_error(...) - vim.api.nvim_err_writeln(string.format(...)) -end - -local commands = { - list = 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() - end) - elseif filter == "notloaded" then - deps = deps:filter(function (dep) - return not Dep.get(dep):is_loaded() - end) - else - vim_error([[No Sloth list filter "%s".]], cmd) - vim_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, - - load = function(plugins) - if #plugins == 0 then - vim_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() - end - end - end, - - version = function() - local version = require('sloth-flake.version') - print(string.format('Sloth v%s', version())) - end, -} - -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) - else - vim.api.nvim_err_writeln(string.format([[No Sloth subcommand "%s"]], cmd)) - end -end - -function M.register() - vim.api.nvim_create_user_command('Sloth', sloth_cmd, { - nargs = '*', - }) -end - -return M diff --git a/lua/sloth-flake/command/init.lua b/lua/sloth-flake/command/init.lua new file mode 100644 index 0000000..ada16a5 --- /dev/null +++ b/lua/sloth-flake/command/init.lua @@ -0,0 +1,29 @@ +local Dep = require 'sloth-flake.dep' + +local M = {} + +local commands = { + list = require 'sloth-flake.command.list', + load = require 'sloth-flake.command.load', + version = require 'sloth-flake.command.version', +} + +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) + else + vim.api.nvim_err_writeln(string.format([[No Sloth subcommand "%s"]], cmd)) + end +end + +function M.register() + vim.api.nvim_create_user_command('Sloth', sloth_cmd, { + nargs = '*', + }) +end + +return M diff --git a/lua/sloth-flake/command/list.lua b/lua/sloth-flake/command/list.lua new file mode 100644 index 0000000..2380222 --- /dev/null +++ b/lua/sloth-flake/command/list.lua @@ -0,0 +1,29 @@ +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() + 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 diff --git a/lua/sloth-flake/command/load.lua b/lua/sloth-flake/command/load.lua new file mode 100644 index 0000000..cd68ddf --- /dev/null +++ b/lua/sloth-flake/command/load.lua @@ -0,0 +1,15 @@ +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() + end + end +end diff --git a/lua/sloth-flake/command/version.lua b/lua/sloth-flake/command/version.lua new file mode 100644 index 0000000..f8a5689 --- /dev/null +++ b/lua/sloth-flake/command/version.lua @@ -0,0 +1,4 @@ +return function() + local version = require('sloth-flake.version') + print(string.format('Sloth v%s', version())) +end diff --git a/lua/sloth-flake/dep.lua b/lua/sloth-flake/dep.lua index dea091a..c5ab24c 100644 --- a/lua/sloth-flake/dep.lua +++ b/lua/sloth-flake/dep.lua @@ -89,7 +89,6 @@ function M:import() end function M:load() - -- unshim_plugin(name) self:unshim() self:init() self:import() diff --git a/lua/sloth-flake/utils.lua b/lua/sloth-flake/utils.lua new file mode 100644 index 0000000..7a3f23b --- /dev/null +++ b/lua/sloth-flake/utils.lua @@ -0,0 +1,7 @@ +local M = {} + +function M.error(...) + vim.api.nvim_err_writeln(string.format(...)) +end + +return M