A fast file manager for Windows and macOS that never freezes: tabs, dual panes, archives as folders, Quick Look-style previews. A File Explorer and Finder alternative written in Rust.
Rust archive-managerdesktop-appdual-paneexplorer-alternativefile-browserfile-explorerfile-managerfluent-designgpu-acceleratedgpuimacosmicaproductivityquick-lookrustrust-guitabswindowswindows-11windows-explorer
Command line: --select <file> opens its folder with the file selected (848)
denfry6fcddfac06db
diff --git a/crates/rf-app/src/lib.rs b/crates/rf-app/src/lib.rsindex f31ecb85..cfdb3940 100644--- a/crates/rf-app/src/lib.rs+++ b/crates/rf-app/src/lib.rs@@ -562,6 +562,45 @@ fn wait_for_the_old_one() {}}+/// The file a command line asks to be shown selected: Explorer's `/select,<file>` (or `-select,`, and `/select, <file>` with the path as+/// the next argument), or `--select <file>` / `--select=<file>` (issue 848). Quotes and spaces around the path are dropped.+fn select_arg(args: &[String]) -> Option<String> {+ let clean = |s: &str| Some(s.trim().trim_matches('"').to_string()).filter(|s| !s.is_empty());+ let first = args.first()?;+ let lower = first.to_ascii_lowercase();+ if lower == "--select" {+ return args.get(1).and_then(|p| clean(p));+ }+ if lower.starts_with("--select=") {+ return clean(&first["--select=".len()..]);+ }+ let all = args.join(" ");+ let lower = all.to_ascii_lowercase();+ (lower.starts_with("/select,") || lower.starts_with("-select,")).then(|| clean(&all[8..])).flatten()+}++#[cfg(test)]+mod select_arg_tests {+ fn sel(args: &[&str]) -> Option<String> {+ super::select_arg(&args.iter().map(|a| a.to_string()).collect::<Vec<_>>())+ }++ #[test]+ fn explorers_select_and_the_dashed_form_name_the_same_file() {+ let want = Some(r"C:\work\a b.txt".to_string());+ assert_eq!(sel(&[r"/select,C:\work\a b.txt"]), want);+ assert_eq!(sel(&[r#"/select,"C:\work\a b.txt""#]), want, "quoted");+ assert_eq!(sel(&["/select,", r"C:\work\a b.txt"]), want, "the path as the next argument");+ assert_eq!(sel(&[r"-SELECT,C:\work\a b.txt"]), want);+ assert_eq!(sel(&["--select", r"C:\work\a b.txt"]), want, "issue 848");+ assert_eq!(sel(&["--SELECT", r#""C:\work\a b.txt""#]), want);+ assert_eq!(sel(&[r"--select=C:\work\a b.txt"]), want);+ assert_eq!(sel(&["--select"]), None, "no path");+ assert_eq!(sel(&[r"C:\work"]), None, "a folder alone is not a selection");+ assert_eq!(sel(&[]), None);+ }+}+/// `Path::is_dir` with a time limit (it can block for the SMB timeout on an offline share).pub(crate) fn is_dir_bounded(p: PathBuf, limit: std::time::Duration) -> Option<bool> {let (tx, rx) = std::sync::mpsc::channel();@@ -703,11 +742,11 @@ pub fn main() {let mut start: Option<Location> = None;// Explorer's `/select,<file>`: its folder, with the file selected// (callers also write `/select, <file>`: the path then comes as the next argument)- let all_args = std::env::args().skip(1).collect::<Vec<_>>().join(" ");+ // (and `--select <file>`, issue 848: the same for scripts and agents that do not know Explorer's form)+ let all_args = std::env::args().skip(1).collect::<Vec<_>>();+ let dashed_select = all_args.first().is_some_and(|a| a.eq_ignore_ascii_case("--select") || a.to_ascii_lowercase().starts_with("--select="));let mut select = {- let lower = all_args.to_ascii_lowercase();- (lower.starts_with("/select,") || lower.starts_with("-select,"))- .then(|| all_args[8..].trim().trim_matches('"').to_string())+ select_arg(&all_args)// bounded like the folder check below: an offline share must not hold the window.filter(|file| {PathBuf::from(file)@@ -715,6 +754,11 @@ pub fn main() {.is_some_and(|d| is_dir_bounded(d.to_path_buf(), std::time::Duration::from_secs(2)) != Some(false))})};+ if dashed_select && select.is_none() {+ // (not handed to Explorer, which knows no `--select`: the caller is told by the exit code)+ log::warn!("--select: no such folder: {:?}", all_args.get(1..));+ std::process::exit(2);+ }let arg = if select.is_some() { None } else { arg };if let Some(file) = &select {let p = PathBuf::from(file);