mirror of
https://github.com/sxyazi/yazi.git
synced 2026-07-25 08:41:05 +00:00
54 lines
1.1 KiB
Rust
54 lines
1.1 KiB
Rust
use yazi_config::{keymap::Exec, open::Opener, popup::InputOpt, INPUT};
|
|
|
|
use crate::{emit, tab::Tab};
|
|
|
|
pub struct Opt {
|
|
cmd: String,
|
|
block: bool,
|
|
confirm: bool,
|
|
}
|
|
|
|
impl<'a> From<&'a Exec> for Opt {
|
|
fn from(e: &'a Exec) -> Self {
|
|
Self {
|
|
cmd: e.args.first().map(|e| e.to_owned()).unwrap_or_default(),
|
|
block: e.named.contains_key("block"),
|
|
confirm: e.named.contains_key("confirm"),
|
|
}
|
|
}
|
|
}
|
|
|
|
impl Tab {
|
|
pub fn shell(&self, opt: impl Into<Opt>) -> bool {
|
|
let selected: Vec<_> = self
|
|
.selected()
|
|
.into_iter()
|
|
.map(|f| (f.url.as_os_str().to_owned(), Default::default()))
|
|
.collect();
|
|
|
|
let mut opt = opt.into() as Opt;
|
|
tokio::spawn(async move {
|
|
if !opt.confirm || opt.cmd.is_empty() {
|
|
let mut result = emit!(Input(InputOpt::shell(opt.block).with_value(opt.cmd)));
|
|
match result.recv().await {
|
|
Some(Ok(e)) => opt.cmd = e,
|
|
_ => return,
|
|
}
|
|
}
|
|
|
|
emit!(Open(
|
|
selected,
|
|
Some(Opener {
|
|
exec: opt.cmd,
|
|
block: opt.block,
|
|
orphan: false,
|
|
desc: Default::default(),
|
|
for_: None,
|
|
spread: true,
|
|
})
|
|
));
|
|
});
|
|
|
|
false
|
|
}
|
|
}
|