mirror of
https://github.com/sxyazi/yazi.git
synced 2024-12-18 22:31:35 +03:00
feat: add command template support for shell
(#48)
This commit is contained in:
parent
1e3b17e58c
commit
0da93562c9
@ -106,7 +106,11 @@ impl Executor {
|
||||
}
|
||||
"create" => cx.manager.create(),
|
||||
"rename" => cx.manager.rename(),
|
||||
"shell" => cx.manager.shell(exec.named.contains_key("block")),
|
||||
"shell" => cx.manager.shell(
|
||||
exec.args.get(0).map(|e| e.as_str()).unwrap_or(""),
|
||||
exec.named.contains_key("block"),
|
||||
exec.named.contains_key("confirm"),
|
||||
),
|
||||
"hidden" => cx.manager.current_mut().hidden(match exec.args.get(0).map(|s| s.as_str()) {
|
||||
Some("show") => Some(true),
|
||||
Some("hide") => Some(false),
|
||||
|
@ -62,7 +62,9 @@
|
||||
- rename: Rename a file or directory.
|
||||
- shell: Run a shell command.
|
||||
|
||||
- `exec`: Optional, command template to be run.
|
||||
- `--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.
|
||||
|
||||
|
@ -225,16 +225,21 @@ impl Manager {
|
||||
|
||||
pub fn bulk_rename(&self) -> bool { false }
|
||||
|
||||
pub fn shell(&self, block: bool) -> bool {
|
||||
pub fn shell(&self, exec: &str, block: bool, confirm: bool) -> bool {
|
||||
let mut exec = exec.to_owned();
|
||||
tokio::spawn(async move {
|
||||
let result = emit!(Input(InputOpt::top("Shell:").with_highlight()));
|
||||
|
||||
if let Ok(exec) = result.await {
|
||||
emit!(Open(
|
||||
Default::default(),
|
||||
Some(Opener { exec, block, display_name: Default::default(), spread: true })
|
||||
));
|
||||
if !confirm || exec.is_empty() {
|
||||
let result = emit!(Input(InputOpt::top("Shell:").with_value(&exec).with_highlight()));
|
||||
match result.await {
|
||||
Ok(e) => exec = e,
|
||||
Err(_) => return,
|
||||
}
|
||||
}
|
||||
|
||||
emit!(Open(
|
||||
Default::default(),
|
||||
Some(Opener { exec, block, display_name: Default::default(), spread: true })
|
||||
));
|
||||
});
|
||||
|
||||
false
|
||||
|
@ -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({
|
||||
let process = self.process.clone();
|
||||
let opener = opener.clone();
|
||||
|
Loading…
Reference in New Issue
Block a user