From e903320d95ecf1587142d2d98171b4cd31985906 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E4=B8=89=E5=92=B2=E9=9B=85=20=C2=B7=20Misaki=20Masa?= Date: Thu, 28 Mar 2024 17:14:11 +0800 Subject: [PATCH] feat: add support for `YAZI_FILE_ONE` to the built-in `file` previewer (#846) --- yazi-plugin/preset/plugins/file.lua | 11 +++-------- yazi-plugin/preset/plugins/mime.lua | 2 +- 2 files changed, 4 insertions(+), 9 deletions(-) diff --git a/yazi-plugin/preset/plugins/file.lua b/yazi-plugin/preset/plugins/file.lua index cd334afa..8e99c6b1 100644 --- a/yazi-plugin/preset/plugins/file.lua +++ b/yazi-plugin/preset/plugins/file.lua @@ -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 diff --git a/yazi-plugin/preset/plugins/mime.lua b/yazi-plugin/preset/plugins/mime.lua index 0e61267d..61327da3 100644 --- a/yazi-plugin/preset/plugins/mime.lua +++ b/yazi-plugin/preset/plugins/mime.lua @@ -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