feat: add preset command to the shell

This commit is contained in:
fzdwx 2023-08-12 19:23:07 +08:00
parent d881614d31
commit 8f7c8ffbfb
2 changed files with 17 additions and 9 deletions

View file

@ -106,7 +106,10 @@ impl Executor {
}
"create" => cx.manager.create(),
"rename" => cx.manager.rename(),
"shell" => cx.manager.shell(exec.named.contains_key("block")),
"shell" => cx.manager.shell(
exec.named.contains_key("block"),
exec.args.get(0).map(|s| s.as_str()).unwrap_or(""),
),
"hidden" => cx.manager.current_mut().hidden(match exec.args.get(0).map(|s| s.as_str()) {
Some("show") => Some(true),
Some("hide") => Some(false),

View file

@ -225,16 +225,21 @@ impl Manager {
pub fn bulk_rename(&self) -> bool { false }
pub fn shell(&self, block: bool) -> bool {
tokio::spawn(async move {
let result = emit!(Input(InputOpt::top("Shell:").with_highlight()));
pub fn shell(&self, block: bool, arg: &str) -> bool {
let mut command = arg.to_string();
if let Ok(exec) = result.await {
emit!(Open(
Default::default(),
Some(Opener { exec, block, display_name: Default::default(), spread: true })
));
tokio::spawn(async move {
if command.is_empty() {
let result = emit!(Input(InputOpt::top("Shell:").with_highlight()));
if let Ok(exec) = result.await {
command = exec;
}
}
emit!(Open(
Default::default(),
Some(Opener { exec: command, block, display_name: Default::default(), spread: true })
));
});
false