feat: add support for YAZI_FILE_ONE to the built-in file previewer (#846)

This commit is contained in:
三咲雅 · Misaki Masa 2024-03-28 17:14:11 +08:00 committed by GitHub
parent f6f2c30709
commit e903320d95
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 4 additions and 9 deletions

View file

@ -1,13 +1,8 @@
local M = {}
function M:peek()
local output, code = Command("file")
:args({
"-bL",
tostring(self.file.url),
})
:stdout(Command.PIPED)
:output()
local cmd = os.getenv("YAZI_FILE_ONE") or "file"
local output, code = Command(cmd):args({ "-bL", tostring(self.file.url) }):stdout(Command.PIPED):output()
local p
if output then
@ -15,7 +10,7 @@ function M:peek()
else
p = ui.Paragraph(self.area, {
ui.Line {
ui.Span("Failed to spawn `file` command, error code: " .. tostring(code)),
ui.Span(string.format("Spawn `%s` command returns %s", cmd, code)),
},
})
end

View file

@ -18,7 +18,7 @@ function M:preload()
local cmd = os.getenv("YAZI_FILE_ONE") or "file"
local child, code = Command(cmd):args({ "-bL", "--mime-type" }):args(urls):stdout(Command.PIPED):spawn()
if not child then
ya.err(string.format("spawn `%s` command returns %s", cmd, code))
ya.err(string.format("Spawn `%s` command returns %s", cmd, code))
return 0
end