feat: prompt users without fzf for the zoxide plugin

Also fixed some local variables that were redefined.
This commit is contained in:
hankertrix 2024-12-30 13:14:11 +08:00
parent 2770e0259c
commit b03a2f4b51

View file

@ -59,10 +59,10 @@ local function empty(cwd)
return not first return not first
end end
local function setup(_, opts) local function setup(_, options)
opts = opts or {} options = options or {}
if opts.update_db then if options.update_db then
ps.sub( ps.sub(
"cd", "cd",
function() function()
@ -88,6 +88,13 @@ local function entry()
end end
local _permit = ya.hide() local _permit = ya.hide()
local fzf, _err = Command("fzf"):arg("--version"):stdout(Command.PIPED):stderr(Command.PIPED):output()
if not fzf then
return fail(string.format("%s\n%s", "`fzf` is required for the `zoxide` plugin.", "Please install `fzf`."))
end
local child, err = Command("zoxide") local child, err = Command("zoxide")
:args({ "query", "-i", "--exclude" }) :args({ "query", "-i", "--exclude" })
:arg(st.cwd) :arg(st.cwd)
@ -104,9 +111,9 @@ local function entry()
return fail("Failed to start `zoxide`, error: " .. err) return fail("Failed to start `zoxide`, error: " .. err)
end end
local output, err = child:wait_with_output() local output, error = child:wait_with_output()
if not output then if not output then
return fail("Cannot read `zoxide` output, error: " .. err) return fail("Cannot read `zoxide` output, error: " .. error)
elseif not output.status.success and output.status.code ~= 130 then elseif not output.status.success and output.status.code ~= 130 then
return fail("`zoxide` exited with error code %s", output.status.code) return fail("`zoxide` exited with error code %s", output.status.code)
end end