From 1ca98cc8759d71a2bf91bd38f234c569ab7ecdc4 Mon Sep 17 00:00:00 2001 From: MikuGeek <56752306+MikuGeek@users.noreply.github.com> Date: Tue, 18 Mar 2025 23:32:11 +0800 Subject: [PATCH] feat: give indication to original filenames in bulk rename --- yazi-core/src/mgr/commands/bulk_rename.rs | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/yazi-core/src/mgr/commands/bulk_rename.rs b/yazi-core/src/mgr/commands/bulk_rename.rs index e05b067b..fce3817a 100644 --- a/yazi-core/src/mgr/commands/bulk_rename.rs +++ b/yazi-core/src/mgr/commands/bulk_rename.rs @@ -26,12 +26,16 @@ impl Mgr { tokio::spawn(async move { let tmp = YAZI.preview.tmpfile("bulk"); let s = old.iter().map(|o| o.as_os_str()).collect::>().join(OsStr::new("\n")); + const DIVIDER: &str = "\n<↑ After ↑> <↓ Before ↓>\n"; + + let content = [&s, OsStr::new(&format!("{}", DIVIDER)), &s].join(OsStr::new("")); + OpenOptions::new() .write(true) .create_new(true) .open(&tmp) .await? - .write_all(s.as_encoded_bytes()) + .write_all(content.as_encoded_bytes()) .await?; defer! { tokio::spawn(fs::remove_file(tmp.clone())); } @@ -45,7 +49,10 @@ impl Mgr { defer!(AppProxy::resume()); AppProxy::stop().await; - let new: Vec<_> = fs::read_to_string(&tmp).await?.lines().map(PathBuf::from).collect(); + let content = fs::read_to_string(&tmp).await?; + + let new: Vec<_> = + content.split(DIVIDER).next().unwrap_or("").lines().map(PathBuf::from).collect(); Self::bulk_rename_do(root, old, new).await }); }