mirror of
https://github.com/sxyazi/yazi.git
synced 2026-07-25 08:41:05 +00:00
fix: open file not work on windows
This commit is contained in:
parent
907ac09e34
commit
2fb908d537
2 changed files with 67 additions and 14 deletions
|
|
@ -1,21 +1,50 @@
|
||||||
local M = {}
|
local M = {}
|
||||||
|
|
||||||
|
local function detect_os()
|
||||||
|
local os_name
|
||||||
|
if os.getenv('OS') then
|
||||||
|
os_name = os.getenv('OS')
|
||||||
|
if os_name:find('Windows') then
|
||||||
|
return 'Windows'
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
local uname_handle = io.popen('uname')
|
||||||
|
if uname_handle then
|
||||||
|
local uname_result = uname_handle:read('*a')
|
||||||
|
uname_handle:close()
|
||||||
|
if uname_result:find('Linux') then
|
||||||
|
return 'Linux'
|
||||||
|
elseif uname_result:find('Darwin') then
|
||||||
|
return 'macOS'
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
return 'Unknown'
|
||||||
|
end
|
||||||
|
|
||||||
function M:peek()
|
function M:peek()
|
||||||
local cmd = os.getenv("YAZI_FILE_ONE") or "file"
|
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 options = detect_os() == 'Windows' and '-b' or '-bL'
|
||||||
|
local output, code = Command(cmd):args({options, tostring(self.file.url)}):stdout(Command.PIPED):output()
|
||||||
|
|
||||||
local p
|
local p
|
||||||
if output then
|
if output then
|
||||||
p = ui.Paragraph.parse(self.area, "----- File Type Classification -----\n\n" .. output.stdout)
|
p = ui.Paragraph.parse(self.area, '----- File Type Classification -----\n\n' .. output.stdout)
|
||||||
else
|
else
|
||||||
p = ui.Paragraph(self.area, {
|
p =
|
||||||
ui.Line(string.format("Spawn `%s` command returns %s", cmd, code)),
|
ui.Paragraph(
|
||||||
})
|
self.area,
|
||||||
|
{
|
||||||
|
ui.Line(string.format('Spawn `%s` command returns %s', cmd, code))
|
||||||
|
}
|
||||||
|
)
|
||||||
end
|
end
|
||||||
|
|
||||||
ya.preview_widgets(self, { p:wrap(ui.Paragraph.WRAP) })
|
ya.preview_widgets(self, {p:wrap(ui.Paragraph.WRAP)})
|
||||||
end
|
end
|
||||||
|
|
||||||
function M:seek() end
|
function M:seek()
|
||||||
|
end
|
||||||
|
|
||||||
return M
|
return M
|
||||||
|
|
|
||||||
|
|
@ -9,6 +9,29 @@ local function match_mimetype(s)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
local function detect_os()
|
||||||
|
local os_name
|
||||||
|
if os.getenv("OS") then
|
||||||
|
os_name = os.getenv("OS")
|
||||||
|
if os_name:find("Windows") then
|
||||||
|
return "Windows"
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
local uname_handle = io.popen("uname")
|
||||||
|
if uname_handle then
|
||||||
|
local uname_result = uname_handle:read("*a")
|
||||||
|
uname_handle:close()
|
||||||
|
if uname_result:find("Linux") then
|
||||||
|
return "Linux"
|
||||||
|
elseif uname_result:find("Darwin") then
|
||||||
|
return "macOS"
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
return "Unknown"
|
||||||
|
end
|
||||||
|
|
||||||
function M:fetch()
|
function M:fetch()
|
||||||
local urls = {}
|
local urls = {}
|
||||||
for _, file in ipairs(self.files) do
|
for _, file in ipairs(self.files) do
|
||||||
|
|
@ -16,7 +39,8 @@ function M:fetch()
|
||||||
end
|
end
|
||||||
|
|
||||||
local cmd = os.getenv("YAZI_FILE_ONE") or "file"
|
local cmd = os.getenv("YAZI_FILE_ONE") or "file"
|
||||||
local child, code = Command(cmd):args({ "-bL", "--mime-type" }):args(urls):stdout(Command.PIPED):spawn()
|
local options = detect_os() == "Windows" and { "-b", "--mime-type" } or { "-bL", "--mime-type" }
|
||||||
|
local child, code = Command(cmd):args(options):args(urls):stdout(Command.PIPED):spawn()
|
||||||
if not child then
|
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
|
return 0
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue