From beb586aed0d41e6fdec5bba7816337fdad905a33 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: Fri, 14 Feb 2025 21:19:13 +0800 Subject: [PATCH] feat: support disk devices with no sub-partitions (#69) --- .github/DISCUSSION_TEMPLATE/1-q-a.yml | 2 ++ mount.yazi/main.lua | 51 +++++++++++++++++---------- 2 files changed, 35 insertions(+), 18 deletions(-) diff --git a/.github/DISCUSSION_TEMPLATE/1-q-a.yml b/.github/DISCUSSION_TEMPLATE/1-q-a.yml index c667e12..ab64c16 100644 --- a/.github/DISCUSSION_TEMPLATE/1-q-a.yml +++ b/.github/DISCUSSION_TEMPLATE/1-q-a.yml @@ -50,5 +50,7 @@ body: label: Checklist description: Before submitting the post, please make sure you have completed the following options: + - label: I have read all the documentation + required: true - label: I have searched the existing discussions/issues required: true diff --git a/mount.yazi/main.lua b/mount.yazi/main.lua index ed91944..b2b6a31 100644 --- a/mount.yazi/main.lua +++ b/mount.yazi/main.lua @@ -144,10 +144,12 @@ function M:reflow() return { self } end function M:redraw() local rows = {} for _, p in ipairs(self.partitions or {}) do - if p.sub == "" then + if not p.sub then rows[#rows + 1] = ui.Row { p.main } + elseif p.sub == "" then + rows[#rows + 1] = ui.Row { p.main, p.label or "", p.dist or "", p.fstype or "" } else - rows[#rows + 1] = ui.Row { p.sub, p.label or "", p.dist or "", p.fstype or "" } + rows[#rows + 1] = ui.Row { " " .. p.sub, p.label or "", p.dist or "", p.fstype or "" } end end @@ -176,26 +178,24 @@ function M.obtain() local tbl = {} local last for _, p in ipairs(fs.partitions()) do - local main, sub - if ya.target_os() == "macos" then - main, sub = p.src:match("^(/dev/disk%d+)(.+)$") - elseif p.src:find("/dev/nvme", 1, true) == 1 then -- /dev/nvme0n1p1 - main, sub = p.src:match("^(/dev/nvme%d+n%d+)(p%d+)$") - elseif p.src:find("/dev/mmcblk", 1, true) == 1 then -- /dev/mmcblk0p1 - main, sub = p.src:match("^(/dev/mmcblk%d+)(p%d+)$") - elseif p.src:find("/dev/sd", 1, true) == 1 then -- /dev/sda1 - main, sub = p.src:match("^(/dev/sd[a-z])(%d+)$") - end - if sub then - if last ~= main then + local main, sub = M.split(p.src) + if main and last ~= main then + if p.src == main then + last, p.main, p.sub, tbl[#tbl + 1] = p.src, p.src, "", p + else last, tbl[#tbl + 1] = main, { src = main, main = main, sub = "" } end - p.main, p.sub, tbl[#tbl + 1] = main, " " .. sub, p + end + if sub then + if tbl[#tbl].sub == "" and tbl[#tbl].main == main then + tbl[#tbl].sub = nil + end + p.main, p.sub, tbl[#tbl + 1] = main, sub, p end end table.sort(M.fillin(tbl), function(a, b) if a.main == b.main then - return a.sub < b.sub + return (a.sub or "") < (b.sub or "") else return a.main > b.main end @@ -203,6 +203,21 @@ function M.obtain() return tbl end +function M.split(src) + local pats = { + { "^/dev/sd[a-z]", "%d+$" }, -- /dev/sda1 + { "^/dev/nvme%d+n%d+", "p%d+$" }, -- /dev/nvme0n1p1 + { "^/dev/mmcblk%d+", "p%d+$" }, -- /dev/mmcblk0p1 + { "^/dev/disk%d+", ".+$" }, -- /dev/disk1s1 + } + for _, p in ipairs(pats) do + local main = src:match(p[1]) + if main then + return main, src:sub(#main + 1):match(p[2]) + end + end +end + function M.fillin(tbl) if ya.target_os() ~= "linux" then return tbl @@ -210,7 +225,7 @@ function M.fillin(tbl) local sources, indices = {}, {} for i, p in ipairs(tbl) do - if p.sub ~= "" and not p.fstype then + if p.sub and not p.fstype then sources[#sources + 1], indices[p.src] = p.src, i end end @@ -235,7 +250,7 @@ function M.operate(type) local active = active_partition() if not active then return - elseif active.sub == "" then + elseif not active.sub then return -- TODO: mount/unmount main disk end