snailed
/
taolf
Archived
2
0
Fork 0
This repository has been archived on 2024-05-03. You can view files and clone it, but cannot push or open issues or pull requests.
taolf/lua/taolf.lua

42 lines
1.1 KiB
Lua

local M = {}
local Config = require("taolf.config")
local api = vim.api
---Setup the Lf plugin
---@param cfg Lf.Config
function M.setup(cfg)
if Config.__loaded then
return
end
cfg = cfg or {}
M.__conf = cfg
Config.init()
api.nvim_create_user_command("Lf", function(tbl)
require("taolf").start(tbl)
end, { nargs = "*", complete = "file" })
end
---Start the file manager
---`nil` can be used as the first parameter to change options and open in CWD
---@param cfg? Lf.Config alternative configuration options
---@overload fun() Empty
function M.start(cfg)
local Lf = require("taolf.main")
-- Only one argument was given
-- `path` is given as a table, which is treated as `cfg`
-- Strict nil checks are needed because `nil` can be given as an argument
if cfg and type(cfg) ~= "table" and type(cfg) ~= nil then
require("taolf.util").error("Argument to lf.start() must be a table or nil")
return
end
cfg = vim.tbl_deep_extend("keep", cfg or {}, Config.data or M.__conf)
Lf:new(cfg):start(cfg.dir)
end
return M