From abb43251fa252568ef0536bdbfb1833f4243a723 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: Wed, 22 Jan 2025 22:00:45 +0800 Subject: [PATCH] feat: apply natural sort to partitions on both Linux and macOS (#2235) --- yazi-fs/src/mounts/linux.rs | 3 ++- yazi-fs/src/mounts/macos.rs | 3 ++- yazi-fs/src/mounts/partition.rs | 2 +- 3 files changed, 5 insertions(+), 3 deletions(-) diff --git a/yazi-fs/src/mounts/linux.rs b/yazi-fs/src/mounts/linux.rs index 37426de0..68deda69 100644 --- a/yazi-fs/src/mounts/linux.rs +++ b/yazi-fs/src/mounts/linux.rs @@ -3,7 +3,7 @@ use std::{borrow::Cow, collections::{HashMap, HashSet}, ffi::{OsStr, OsString}, use anyhow::Result; use tokio::{io::{Interest, unix::AsyncFd}, time::sleep}; use tracing::error; -use yazi_shared::{replace_cow, replace_vec_cow}; +use yazi_shared::{natsort, replace_cow, replace_vec_cow}; use super::{Locked, Partition, Partitions}; @@ -77,6 +77,7 @@ impl Partitions { let mut set: HashSet<&OsStr> = set.iter().map(AsRef::as_ref).collect(); mounts.iter().filter_map(|p| p.dev_name()).for_each(|s| _ = set.remove(s)); mounts.extend(set.into_iter().map(Partition::new)); + mounts.sort_unstable_by(|a, b| natsort(a.src.as_bytes(), b.src.as_bytes(), false)); }; let labels = Self::labels()?; diff --git a/yazi-fs/src/mounts/macos.rs b/yazi-fs/src/mounts/macos.rs index bb95ca06..ae0e1fbb 100644 --- a/yazi-fs/src/mounts/macos.rs +++ b/yazi-fs/src/mounts/macos.rs @@ -7,6 +7,7 @@ use objc::{msg_send, runtime::Object, sel, sel_impl}; use scopeguard::defer; use tracing::error; use yazi_ffi::{CFDict, CFString, DADiskCopyDescription, DADiskCreateFromBSDName, DARegisterDiskAppearedCallback, DARegisterDiskDescriptionChangedCallback, DARegisterDiskDisappearedCallback, DASessionCreate, DASessionScheduleWithRunLoop, IOIteratorNext, IOObjectRelease, IORegistryEntryCreateCFProperty, IOServiceGetMatchingServices, IOServiceMatching}; +use yazi_shared::natsort; use super::{Locked, Partition, Partitions}; @@ -145,7 +146,7 @@ impl Partitions { } } - names.sort_unstable(); + names.sort_unstable_by(|a, b| natsort(a.as_bytes(), b.as_bytes(), false)); Ok(names) } diff --git a/yazi-fs/src/mounts/partition.rs b/yazi-fs/src/mounts/partition.rs index ccf453aa..e2ca7f29 100644 --- a/yazi-fs/src/mounts/partition.rs +++ b/yazi-fs/src/mounts/partition.rs @@ -22,7 +22,7 @@ impl Partition { let b: &[u8] = self.fstype.as_ref().map_or(b"", |s| s.as_encoded_bytes()); #[cfg(target_os = "linux")] { - matches!(b, b"autofs" | b"binfmt_misc" | b"bpf" | b"cgroup2" | b"configfs" | b"debugfs" | b"devpts" | b"devtmpfs" | b"fuse.gvfsd-fuse" | b"fusectl" | b"hugetlbfs" | b"mqueue" | b"proc" | b"ramfs" | b"securityfs" | b"sysfs" | b"tmpfs") + matches!(b, b"autofs" | b"binfmt_misc" | b"bpf" | b"cgroup2" | b"configfs" | b"debugfs" | b"devpts" | b"devtmpfs" | b"fuse.gvfsd-fuse" | b"fusectl" | b"hugetlbfs" | b"mqueue" | b"proc" | b"pstore" | b"ramfs" | b"securityfs" | b"sysfs" | b"tmpfs" | b"tracefs") } #[cfg(target_os = "macos")] {