fix bugs
This commit is contained in:
parent
38e37900fa
commit
9285a5a205
|
@ -19,8 +19,9 @@ require("taolf").setup({
|
|||
dir = "", -- The dir to start lf in. "gwd" expands to the git working directory.
|
||||
}
|
||||
|
||||
vim.keymap.set("n", "a<Leader>el", require("lf").start, { desc = "Open Lf" })
|
||||
vim.keymap.set("n", "<Leader>ec", function() require("lf").start() end,
|
||||
vim.keymap.set("n", "<Leader>el", function() require("lf").start() end,
|
||||
{ desc = "Open Lf in last directory" })
|
||||
vim.keymap.set("n", "<Leader>ec", function() require("lf").start({ dir = "cwd"}) 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" })
|
||||
|
@ -41,7 +42,7 @@ lazy.nvim setup:
|
|||
},
|
||||
dependencies = { "akinsho/toggleterm.nvim" },
|
||||
keys = {
|
||||
{ "<Leader>el", require("taolf").start, desc = "Open Lf" },
|
||||
{ "<Leader>el", function() require("taolf").start() end, desc = "Open Lf in last directory" },
|
||||
{ "<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" },
|
||||
}
|
||||
|
|
|
@ -16,10 +16,10 @@ local default = {
|
|||
---Validate configuration values
|
||||
---@param cfg Lf.Config existing configuration options
|
||||
local function validate(cfg)
|
||||
assert(vim.validate({
|
||||
vim.validate({
|
||||
default_cmd = { cfg.default_cmd, "s", false },
|
||||
dir = { cfg.dir, "s", false },
|
||||
}))
|
||||
})
|
||||
end
|
||||
|
||||
---Set a configuration passed as a function argument (not through `setup`)
|
||||
|
|
|
@ -55,7 +55,7 @@ end
|
|||
---Start the underlying terminal
|
||||
---@param path? string path where `Lf` starts (reads from `Config` if none, else CWD)
|
||||
function Lf:start(path)
|
||||
self:__open_in(path or self.cfg.dir)
|
||||
if path then self:__open_in(path) end
|
||||
self:__set_cmd_wrapper()
|
||||
|
||||
self.term.on_open = function(term)
|
||||
|
@ -77,33 +77,37 @@ end
|
|||
---@param path? string
|
||||
---@return Lf?
|
||||
function Lf:__open_in(path)
|
||||
if path == "gwd" then
|
||||
local gitdir = fn.system(("git -C %s rev-parse --show-toplevel"):format(fn.expand("%:p:h")))
|
||||
local fwd = fn.expand("%:p:h")
|
||||
|
||||
if gitdir:match("^fatal:.*") then
|
||||
require("util").error("Failed to find git working directory.")
|
||||
path = nil
|
||||
if path then
|
||||
if path == "gwd" then
|
||||
local gitdir = fn.system(("git -C %s rev-parse --show-toplevel"):format(fn.expand("%:p:h")))
|
||||
|
||||
if gitdir:match("^fatal:.*") then
|
||||
require("util").error("Failed to find git working directory.")
|
||||
path = fwd
|
||||
else
|
||||
path = vim.trim(gitdir)
|
||||
end
|
||||
elseif path == "cwd" then
|
||||
path = fwd
|
||||
elseif path then
|
||||
path = fn.expand(path)
|
||||
end
|
||||
|
||||
path = vim.trim(gitdir)
|
||||
end
|
||||
local stat = uv.fs_stat(path)
|
||||
if not type(stat) == "table" then
|
||||
local cwd = uv.cwd() --[[@as string]]
|
||||
stat = uv.fs_stat(cwd)
|
||||
path = cwd
|
||||
end
|
||||
|
||||
if path == nil then
|
||||
path = fn.expand("%:p:h")
|
||||
-- Should be fine, but just checking
|
||||
if stat and not stat.type == "directory" then
|
||||
path = fn.fnamemodify(path, ":h")
|
||||
end
|
||||
else
|
||||
path = fn.expand(path)
|
||||
end
|
||||
|
||||
local stat = uv.fs_stat(path)
|
||||
if not type(stat) == "table" then
|
||||
local cwd = uv.cwd() --[[@as string]]
|
||||
stat = uv.fs_stat(cwd)
|
||||
path = cwd
|
||||
end
|
||||
|
||||
-- Should be fine, but just checking
|
||||
if stat and not stat.type == "directory" then
|
||||
path = fn.fnamemodify(path, ":h")
|
||||
path = nil
|
||||
end
|
||||
|
||||
self.term.dir = path
|
||||
|
|
Reference in New Issue