mirror of
https://github.com/sxyazi/yazi.git
synced 2026-07-25 08:41:05 +00:00
Simplify the code
This commit is contained in:
parent
505ad6b4a3
commit
9d32748ed7
1 changed files with 11 additions and 13 deletions
|
|
@ -9,7 +9,7 @@ local set_state = ya.sync(function(st, empty) st.empty = empty end)
|
||||||
|
|
||||||
local function fail(s, ...) ya.notify { title = "Zoxide", content = s:format(...), timeout = 5, level = "error" } end
|
local function fail(s, ...) ya.notify { title = "Zoxide", content = s:format(...), timeout = 5, level = "error" } end
|
||||||
|
|
||||||
local function opts()
|
local function options()
|
||||||
-- https://github.com/ajeetdsouza/zoxide/blob/main/src/cmd/query.rs#L92
|
-- https://github.com/ajeetdsouza/zoxide/blob/main/src/cmd/query.rs#L92
|
||||||
local default = {
|
local default = {
|
||||||
-- Search mode
|
-- Search mode
|
||||||
|
|
@ -59,10 +59,10 @@ local function empty(cwd)
|
||||||
return not first
|
return not first
|
||||||
end
|
end
|
||||||
|
|
||||||
local function setup(_, options)
|
local function setup(_, opts)
|
||||||
options = options or {}
|
opts = opts or {}
|
||||||
|
|
||||||
if options.update_db then
|
if opts.update_db then
|
||||||
ps.sub(
|
ps.sub(
|
||||||
"cd",
|
"cd",
|
||||||
function()
|
function()
|
||||||
|
|
@ -89,29 +89,27 @@ local function entry()
|
||||||
|
|
||||||
local _permit = ya.hide()
|
local _permit = ya.hide()
|
||||||
|
|
||||||
local child, err = Command("zoxide")
|
local child, err1 = Command("zoxide")
|
||||||
:args({ "query", "-i", "--exclude" })
|
:args({ "query", "-i", "--exclude" })
|
||||||
:arg(st.cwd)
|
:arg(st.cwd)
|
||||||
:env("SHELL", "sh")
|
:env("SHELL", "sh")
|
||||||
:env("CLICOLOR", "1")
|
:env("CLICOLOR", "1")
|
||||||
:env("CLICOLOR_FORCE", "1")
|
:env("CLICOLOR_FORCE", "1")
|
||||||
:env("_ZO_FZF_OPTS", opts())
|
:env("_ZO_FZF_OPTS", options())
|
||||||
:stdin(Command.INHERIT)
|
:stdin(Command.INHERIT)
|
||||||
:stdout(Command.PIPED)
|
:stdout(Command.PIPED)
|
||||||
:stderr(Command.INHERIT)
|
:stderr(Command.PIPED)
|
||||||
:spawn()
|
:spawn()
|
||||||
|
|
||||||
if not child then
|
if not child then
|
||||||
return fail("Failed to start `zoxide`, error: " .. err)
|
return fail("Failed to start `zoxide`, error: " .. err1)
|
||||||
end
|
end
|
||||||
|
|
||||||
local output, error = child:wait_with_output()
|
local output, err2 = child:wait_with_output()
|
||||||
if not output then
|
if not output then
|
||||||
return fail("Cannot read `zoxide` output, error: " .. error)
|
return fail("Cannot read `zoxide` output, error: " .. err2)
|
||||||
elseif output.stderr:find("could not find") then
|
|
||||||
return fail(output.stderr)
|
|
||||||
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 code %s: %s", output.status.code, output.stderr:gsub("^zoxide:%s+", ""))
|
||||||
end
|
end
|
||||||
|
|
||||||
local target = output.stdout:gsub("\n$", "")
|
local target = output.stdout:gsub("\n$", "")
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue