This commit is contained in:
sxyazi 2023-08-12 23:49:01 +08:00
parent 085c003b1b
commit 6312f17edb
No known key found for this signature in database
4 changed files with 12 additions and 12 deletions

View file

@ -107,9 +107,9 @@ impl Executor {
"create" => cx.manager.create(), "create" => cx.manager.create(),
"rename" => cx.manager.rename(), "rename" => cx.manager.rename(),
"shell" => cx.manager.shell( "shell" => cx.manager.shell(
exec.args.get(0).map(|e| e.as_str()).unwrap_or(""),
exec.named.contains_key("block"), exec.named.contains_key("block"),
exec.named.contains_key("confirm"), exec.named.contains_key("confirm"),
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()) { "hidden" => cx.manager.current_mut().hidden(match exec.args.get(0).map(|s| s.as_str()) {
Some("show") => Some(true), Some("show") => Some(true),

View file

@ -62,7 +62,9 @@
- rename: Rename a file or directory. - rename: Rename a file or directory.
- shell: Run a shell command. - shell: Run a shell command.
- `exec`: Optional, command template to be run.
- `--block`: Block the UI until the command finishes. - `--block`: Block the UI until the command finishes.
- `--confirm`: When the template is provided, run it directly, no input UI was shown.
- hidden: Set the visibility of hidden files. - hidden: Set the visibility of hidden files.

View file

@ -225,22 +225,20 @@ impl Manager {
pub fn bulk_rename(&self) -> bool { false } pub fn bulk_rename(&self) -> bool { false }
pub fn shell(&self, block: bool, confirm: bool, arg: &str) -> bool { pub fn shell(&self, exec: &str, block: bool, confirm: bool) -> bool {
let mut command = arg.to_string(); let mut exec = exec.to_owned();
tokio::spawn(async move { tokio::spawn(async move {
if confirm || command.is_empty() { if !confirm || exec.is_empty() {
let opt = InputOpt::top("Shell:").with_value(command.as_str()).with_highlight(); let result = emit!(Input(InputOpt::top("Shell:").with_value(&exec).with_highlight()));
let result = emit!(Input(opt)); match result.await {
Ok(e) => exec = e,
if let Ok(exec) = result.await { Err(_) => return,
command = exec;
} }
} }
emit!(Open( emit!(Open(
Default::default(), Default::default(),
Some(Opener { exec: command, block, display_name: Default::default(), spread: true }) Some(Opener { exec, block, display_name: Default::default(), spread: true })
)); ));
}); });

View file

@ -302,7 +302,7 @@ impl Scheduler {
}) })
}); });
let args = args.into_iter().map(|a| a.as_ref().to_os_string()).collect::<Vec<_>>(); let args = args.iter().map(|a| a.as_ref().to_os_string()).collect::<Vec<_>>();
tokio::spawn({ tokio::spawn({
let process = self.process.clone(); let process = self.process.clone();
let opener = opener.clone(); let opener = opener.clone();