mirror of
https://github.com/sxyazi/yazi.git
synced 2026-07-21 14:51:03 +00:00
feat: new force option added for the remove command, which does not show the confirmation dialog on trashing/deleting (#173)
This commit is contained in:
parent
afab7879dd
commit
1793d635eb
3 changed files with 27 additions and 13 deletions
|
|
@ -110,7 +110,9 @@ impl Executor {
|
||||||
}
|
}
|
||||||
"remove" => {
|
"remove" => {
|
||||||
let targets = cx.manager.selected().into_iter().map(|f| f.url_owned()).collect();
|
let targets = cx.manager.selected().into_iter().map(|f| f.url_owned()).collect();
|
||||||
cx.tasks.file_remove(targets, exec.named.contains_key("permanently"))
|
let force = exec.named.contains_key("force");
|
||||||
|
let permanently = exec.named.contains_key("permanently");
|
||||||
|
cx.tasks.file_remove(targets, force, permanently)
|
||||||
}
|
}
|
||||||
"create" => cx.manager.create(),
|
"create" => cx.manager.create(),
|
||||||
"rename" => cx.manager.rename(),
|
"rename" => cx.manager.rename(),
|
||||||
|
|
|
||||||
|
|
@ -60,6 +60,7 @@
|
||||||
|
|
||||||
- remove: Move the files to the trash/recycle bin.
|
- remove: Move the files to the trash/recycle bin.
|
||||||
|
|
||||||
|
- `--force`: Don't show the confirmation dialog, and trash/delete the files directly.
|
||||||
- `--permanently`: Permanently delete the files.
|
- `--permanently`: Permanently delete the files.
|
||||||
|
|
||||||
- create: Create a file or directory (ends with `/` for directories).
|
- create: Create a file or directory (ends with `/` for directories).
|
||||||
|
|
|
||||||
|
|
@ -156,30 +156,41 @@ impl Tasks {
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn file_cut(&self, src: &HashSet<Url>, dest: Url, force: bool) -> bool {
|
pub fn file_cut(&self, src: &HashSet<Url>, dest: Url, force: bool) -> bool {
|
||||||
for p in src {
|
for u in src {
|
||||||
let to = dest.join(p.file_name().unwrap());
|
let to = dest.join(u.file_name().unwrap());
|
||||||
if force && p == &to {
|
if force && u == &to {
|
||||||
trace!("file_cut: same file, skipping {:?}", to);
|
trace!("file_cut: same file, skipping {:?}", to);
|
||||||
} else {
|
} else {
|
||||||
self.scheduler.file_cut(p.clone(), to, force);
|
self.scheduler.file_cut(u.clone(), to, force);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
false
|
false
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn file_copy(&self, src: &HashSet<Url>, dest: Url, force: bool, follow: bool) -> bool {
|
pub fn file_copy(&self, src: &HashSet<Url>, dest: Url, force: bool, follow: bool) -> bool {
|
||||||
for p in src {
|
for u in src {
|
||||||
let to = dest.join(p.file_name().unwrap());
|
let to = dest.join(u.file_name().unwrap());
|
||||||
if force && p == &to {
|
if force && u == &to {
|
||||||
trace!("file_copy: same file, skipping {:?}", to);
|
trace!("file_copy: same file, skipping {:?}", to);
|
||||||
} else {
|
} else {
|
||||||
self.scheduler.file_copy(p.clone(), to, force, follow);
|
self.scheduler.file_copy(u.clone(), to, force, follow);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
false
|
false
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn file_remove(&self, targets: Vec<Url>, permanently: bool) -> bool {
|
pub fn file_remove(&self, targets: Vec<Url>, force: bool, permanently: bool) -> bool {
|
||||||
|
if force {
|
||||||
|
for u in targets {
|
||||||
|
if permanently {
|
||||||
|
self.scheduler.file_delete(u);
|
||||||
|
} else {
|
||||||
|
self.scheduler.file_trash(u);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
let scheduler = self.scheduler.clone();
|
let scheduler = self.scheduler.clone();
|
||||||
tokio::spawn(async move {
|
tokio::spawn(async move {
|
||||||
let s = if targets.len() > 1 { "s" } else { "" };
|
let s = if targets.len() > 1 { "s" } else { "" };
|
||||||
|
|
@ -193,11 +204,11 @@ impl Tasks {
|
||||||
if choice != "y" && choice != "Y" {
|
if choice != "y" && choice != "Y" {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
for p in targets {
|
for u in targets {
|
||||||
if permanently {
|
if permanently {
|
||||||
scheduler.file_delete(p);
|
scheduler.file_delete(u);
|
||||||
} else {
|
} else {
|
||||||
scheduler.file_trash(p);
|
scheduler.file_trash(u);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue