snailed
/
taolf
Archived
2
0
Fork 0
This commit is contained in:
Luca Bilke 2024-01-29 10:41:16 +01:00
parent 612456bb25
commit c9d441f235
5 changed files with 24 additions and 25 deletions

View File

@ -15,13 +15,17 @@ process with lazy.nvim a tiny bit.
Setup:
```lua
require("taolf").setup({
default_cmd = "lf", -- The Command to start lf with.
dir = "", -- The dir to start lf in. "gwd" expands to the git working directory.
-- The Command to start lf with.
default_cmd = "lf",
-- The dir to start lf in.
-- "gwd" expands to the git working directory.
-- "fd" expands to the open file's directory.
dir = "",
}
vim.keymap.set("n", "<Leader>el", function() require("lf").start() end,
{ desc = "Open Lf" })
vim.keymap.set("n", "<Leader>ec", function() require("lf").start({ dir = "cwd"}) end,
vim.keymap.set("n", "<Leader>ec", function() require("lf").start({ dir = "fd"}) end,
{ desc = "Open Lf in directory of open file" })
vim.keymap.set("n", "<Leader>eg", function() require("lf").start({ dir = "gwd" }) end,
{ desc = "Open Lf in git working directory" })
@ -38,13 +42,14 @@ lazy.nvim setup:
-- The path to start lf in.
-- "gwd" expands to the git working directory
-- "fd" expands to the open file's directory
dir = "", -- The path to start lf in.
},
dependencies = { "akinsho/toggleterm.nvim" },
keys = {
{ "<Leader>el", function() require("taolf").start() end, desc = "Open Lf" },
{ "<Leader>ec", function() require("taolf").start({ dir = "cwd" }) end, desc = "Open Lf in directory of open file" },
{ "<Leader>eg", function() require("taolf").start({ dir = "gwd" }) end, desc = "Open Lf in git working directory" },
{ "<Leader>eg", function() require("taolf").start({ dir = "fd" }) end, desc = "Open Lf in git working directory" },
}
}
```

View File

@ -1,5 +0,0 @@
{
"diagnostics.globals": [
"vim"
]
}

View File

@ -55,7 +55,7 @@ function M.setup(cfg)
group = group,
pattern = "*",
nested = true,
callback = function(a)
callback = function(_)
if vim.fn.exists("#FileExplorer") then
api.nvim_create_augroup("FileExplorer", { clear = true })
end
@ -89,12 +89,12 @@ function M.start(cfg)
-- `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("util").error("Argument to lf.start() must be a table or nil")
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()
Lf:new(cfg):start(cfg.dir)
end
return M

View File

@ -17,8 +17,8 @@ local default = {
---@param cfg Lf.Config existing configuration options
local function validate(cfg)
vim.validate({
default_cmd = { cfg.default_cmd, "s", false },
dir = { cfg.dir, "s", false },
default_cmd = { cfg.default_cmd, { "string", "nil" } },
dir = { cfg.dir, { "string", "nil" } },
})
end
@ -63,6 +63,6 @@ return setmetatable(Config, {
end,
---@diagnostic disable-next-line: unused-local
__newindex = function(self, key, val)
vim.echo(("do not set invalid config values: %s => %s"):format(key, val))
require("taolf.util").error(("do not set invalid config values: %s => %s"):format(key, val))
end,
})

View File

@ -76,20 +76,21 @@ end
---@param path? string
---@return Lf?
function Lf:__open_in(path)
local file_wd = fn.expand("%:p:h")
local file_directory = fn.expand("%:p:h")
if path then
if path == "gwd" then
local gitdir = fn.system(("git -C %s rev-parse --show-toplevel"):format(file_wd))
local gitdir = fn.system(("git -C %s rev-parse --show-toplevel"):format(file_directory))
if gitdir:match("^fatal:.*") ~= nil then
require("util").error("Failed to find git working directory.")
path = file_wd
require("taolf.util").error("Failed to find git working directory.")
else
path = vim.trim(gitdir)
end
elseif path == "cwd" then
path = file_wd
elseif path == "fd" then
path = file_directory
end
else
path = Config.dir or ""
end
if path == nil or type(uv.fs_stat(path)) ~= "table" then
@ -98,8 +99,6 @@ function Lf:__open_in(path)
self.term.dir = path
self.curfile = fn.expand("%:p")
return self
end
---@private
@ -110,9 +109,9 @@ function Lf:__set_cmd_wrapper()
self.tmp_lastdir = os.tmpname()
self.tmp_id = os.tmpname()
local selection = self.term.dir or ""
local selection = self.term.dir
if fn.fnamemodify(self.curfile, ":h") == self.term.dir then
selection = self.curfil
selection = self.curfile
end
self.term.cmd =