From 31fccd4052d87273da884675ca5fd9c0d7ae9e7f Mon Sep 17 00:00:00 2001 From: MikuGeek <56752306+MikuGeek@users.noreply.github.com> Date: Mon, 24 Mar 2025 23:52:26 +0800 Subject: [PATCH] feat: allow bulk renaming to include trailing content in addition to the required new names (#2494) Co-authored-by: sxyazi --- yazi-core/src/mgr/commands/bulk_rename.rs | 9 +++++++-- 1 file changed, 7 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..b398f899 100644 --- a/yazi-core/src/mgr/commands/bulk_rename.rs +++ b/yazi-core/src/mgr/commands/bulk_rename.rs @@ -1,6 +1,7 @@ use std::{borrow::Cow, collections::HashMap, ffi::{OsStr, OsString}, io::{Read, Write}, path::PathBuf}; use anyhow::{Result, anyhow}; +use crossterm::{execute, style::Print}; use scopeguard::defer; use tokio::{fs::{self, OpenOptions}, io::AsyncWriteExt}; use yazi_config::YAZI; @@ -45,7 +46,8 @@ impl Mgr { defer!(AppProxy::resume()); AppProxy::stop().await; - let new: Vec<_> = fs::read_to_string(&tmp).await?.lines().map(PathBuf::from).collect(); + let new: Vec<_> = + fs::read_to_string(&tmp).await?.lines().take(old.len()).map(PathBuf::from).collect(); Self::bulk_rename_do(root, old, new).await }); } @@ -53,7 +55,10 @@ impl Mgr { async fn bulk_rename_do(root: PathBuf, old: Vec, new: Vec) -> Result<()> { terminal_clear(TTY.writer())?; if old.len() != new.len() { - TTY.writer().write_all(b"Number of old and new differ, press ENTER to exit")?; + #[rustfmt::skip] + let s = format!("Number of new and old file names mismatch (New: {}, Old: {}).\nPress to exit...", new.len(), old.len()); + execute!(TTY.writer(), Print(s))?; + TTY.reader().read_exact(&mut [0])?; return Ok(()); }