From d57444d336a9e8264178733c59dacb4bfa572ed1 Mon Sep 17 00:00:00 2001 From: Rolf K Date: Sat, 17 Aug 2024 10:38:44 +0200 Subject: [PATCH 1/3] Add --dir option to 'create' command This allows you to bind 'create --dir' to a key, to create directories without having to remember to put / or \ at the end. --- yazi-core/src/manager/commands/create.rs | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/yazi-core/src/manager/commands/create.rs b/yazi-core/src/manager/commands/create.rs index 351b40b5d..1f1834f38 100644 --- a/yazi-core/src/manager/commands/create.rs +++ b/yazi-core/src/manager/commands/create.rs @@ -4,16 +4,22 @@ use anyhow::Result; use tokio::fs; use yazi_config::popup::InputCfg; use yazi_proxy::{InputProxy, TabProxy, WATCHER}; -use yazi_shared::{event::Cmd, fs::{maybe_exists, ok_or_not_found, symlink_realpath, File, FilesOp, Url}}; +use yazi_shared::{ + event::Cmd, + fs::{maybe_exists, ok_or_not_found, symlink_realpath, File, FilesOp, Url}, +}; use crate::manager::Manager; pub struct Opt { force: bool, + dir: bool, } impl From for Opt { - fn from(c: Cmd) -> Self { Self { force: c.bool("force") } } + fn from(c: Cmd) -> Self { + Self { force: c.bool("force"), dir: c.bool("dir") } + } } impl Manager { @@ -37,7 +43,7 @@ impl Manager { } } - Self::create_do(new, name.ends_with('/') || name.ends_with('\\')).await + Self::create_do(new, opt.dir || name.ends_with('/') || name.ends_with('\\')).await }); } From 01c53c91dfb792eab186eb6fb1556962d0bea00b Mon Sep 17 00:00:00 2001 From: Rolf K Date: Sat, 17 Aug 2024 10:51:48 +0200 Subject: [PATCH 2/3] Run rustfmt --- yazi-core/src/manager/commands/create.rs | 11 +++-------- 1 file changed, 3 insertions(+), 8 deletions(-) diff --git a/yazi-core/src/manager/commands/create.rs b/yazi-core/src/manager/commands/create.rs index 1f1834f38..873a6d18b 100644 --- a/yazi-core/src/manager/commands/create.rs +++ b/yazi-core/src/manager/commands/create.rs @@ -4,22 +4,17 @@ use anyhow::Result; use tokio::fs; use yazi_config::popup::InputCfg; use yazi_proxy::{InputProxy, TabProxy, WATCHER}; -use yazi_shared::{ - event::Cmd, - fs::{maybe_exists, ok_or_not_found, symlink_realpath, File, FilesOp, Url}, -}; +use yazi_shared::{event::Cmd, fs::{maybe_exists, ok_or_not_found, symlink_realpath, File, FilesOp, Url}}; use crate::manager::Manager; pub struct Opt { force: bool, - dir: bool, + dir: bool, } impl From for Opt { - fn from(c: Cmd) -> Self { - Self { force: c.bool("force"), dir: c.bool("dir") } - } + fn from(c: Cmd) -> Self { Self { force: c.bool("force"), dir: c.bool("dir") } } } impl Manager { From 6a1a6cb600c764729f4e1f6dd9caa441f5350d3d Mon Sep 17 00:00:00 2001 From: sxyazi Date: Wed, 21 Aug 2024 00:33:56 +0800 Subject: [PATCH 3/3] Refactor the order of the fields in the `Opt` struct --- yazi-core/src/manager/commands/create.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/yazi-core/src/manager/commands/create.rs b/yazi-core/src/manager/commands/create.rs index 873a6d18b..a9e223cef 100644 --- a/yazi-core/src/manager/commands/create.rs +++ b/yazi-core/src/manager/commands/create.rs @@ -9,12 +9,12 @@ use yazi_shared::{event::Cmd, fs::{maybe_exists, ok_or_not_found, symlink_realpa use crate::manager::Manager; pub struct Opt { - force: bool, dir: bool, + force: bool, } impl From for Opt { - fn from(c: Cmd) -> Self { Self { force: c.bool("force"), dir: c.bool("dir") } } + fn from(c: Cmd) -> Self { Self { dir: c.bool("dir"), force: c.bool("force") } } } impl Manager {