mirror of
https://github.com/sxyazi/yazi.git
synced 2024-12-18 22:31:35 +03:00
feat: running shell (#24)
This commit is contained in:
parent
c5c9b2e598
commit
2f32ca17cb
@ -102,6 +102,7 @@ impl Executor {
|
||||
}
|
||||
"create" => cx.manager.create(),
|
||||
"rename" => cx.manager.rename(),
|
||||
"shell" => cx.manager.shell(exec.named.contains_key("block")),
|
||||
"hidden" => cx.manager.current_mut().hidden(match exec.args.get(0).map(|s| s.as_str()) {
|
||||
Some("show") => Some(true),
|
||||
Some("hide") => Some(false),
|
||||
|
@ -42,7 +42,7 @@
|
||||
|
||||
- open: Open the selected files.
|
||||
|
||||
- `--interactive`: Open the selected files with an interactive ui to choose the opening method.
|
||||
- `--interactive`: Open the selected files with an interactive UI to choose the opening method.
|
||||
|
||||
- yank: Copy the selected files.
|
||||
|
||||
@ -59,6 +59,10 @@
|
||||
|
||||
- create: Create a file or directory (ends with `/` for directory).
|
||||
- rename: Rename a file or directory.
|
||||
- shell: Run a shell command.
|
||||
|
||||
- `--block`: Block the UI until the command finishes.
|
||||
|
||||
- hidden: Set the visibility of hidden files.
|
||||
|
||||
- `show`: Show hidden files.
|
||||
|
@ -45,6 +45,8 @@ keymap = [
|
||||
{ on = [ "D" ], exec = "remove --permanently" },
|
||||
{ on = [ "a" ], exec = "create" },
|
||||
{ on = [ "r" ], exec = "rename" },
|
||||
{ on = [ ";" ], exec = "shell" },
|
||||
{ on = [ ":" ], exec = "shell --block" },
|
||||
{ on = [ "." ], exec = "hidden toggle" },
|
||||
{ on = [ "s" ], exec = "search fd" },
|
||||
{ on = [ "S" ], exec = "search rg" },
|
||||
|
@ -1,4 +1,4 @@
|
||||
use std::{collections::BTreeMap, path::PathBuf};
|
||||
use std::{collections::BTreeMap, ffi::OsString, path::PathBuf};
|
||||
|
||||
use anyhow::Result;
|
||||
use config::{keymap::{Control, KeymapLayer}, open::Opener};
|
||||
@ -32,7 +32,7 @@ pub enum Event {
|
||||
Input(InputOpt, oneshot::Sender<Result<String>>),
|
||||
|
||||
// Tasks
|
||||
Open(Vec<(PathBuf, String)>, Option<Opener>),
|
||||
Open(Vec<(OsString, String)>, Option<Opener>),
|
||||
Progress(u8, u32),
|
||||
}
|
||||
|
||||
|
@ -1,7 +1,7 @@
|
||||
use std::{collections::{BTreeMap, BTreeSet, HashMap, HashSet}, env, mem, path::PathBuf};
|
||||
|
||||
use anyhow::Error;
|
||||
use config::OPEN;
|
||||
use config::{open::Opener, OPEN};
|
||||
use shared::MIME_DIR;
|
||||
use tokio::fs;
|
||||
|
||||
@ -126,7 +126,7 @@ impl Manager {
|
||||
.into_iter()
|
||||
.map(|f| {
|
||||
(
|
||||
f.path(),
|
||||
f.path().into_os_string(),
|
||||
if f.meta.is_dir() {
|
||||
Some(MIME_DIR.to_owned())
|
||||
} else {
|
||||
@ -146,7 +146,7 @@ impl Manager {
|
||||
files = files
|
||||
.into_iter()
|
||||
.map(|(p, m)| {
|
||||
let mime = m.or_else(|| mimes.remove(&p));
|
||||
let mime = m.or_else(|| mimes.remove(&PathBuf::from(&p)));
|
||||
(p, mime)
|
||||
})
|
||||
.collect::<Vec<_>>();
|
||||
@ -231,10 +231,30 @@ impl Manager {
|
||||
false
|
||||
}
|
||||
|
||||
fn bulk_rename(&self) -> bool { false }
|
||||
pub fn bulk_rename(&self) -> bool { false }
|
||||
|
||||
pub fn selected(&self) -> Vec<&File> {
|
||||
self.current().selected().or_else(|| self.hovered().map(|h| vec![h])).unwrap_or_default()
|
||||
pub fn shell(&self, block: bool) -> bool {
|
||||
tokio::spawn(async move {
|
||||
let result = emit!(Input(InputOpt {
|
||||
title: "Shell:".to_string(),
|
||||
value: "".to_string(),
|
||||
position: Position::Top,
|
||||
}));
|
||||
|
||||
if let Ok(cmd) = result.await {
|
||||
emit!(Open(
|
||||
vec![(cmd.into(), "".to_string())],
|
||||
Some(Opener {
|
||||
cmd: "sh".to_string(),
|
||||
args: vec!["-c".to_string(), "$0".to_string()],
|
||||
block,
|
||||
spread: false,
|
||||
})
|
||||
));
|
||||
}
|
||||
});
|
||||
|
||||
false
|
||||
}
|
||||
|
||||
pub fn update_read(&mut self, op: FilesOp) -> bool {
|
||||
@ -352,4 +372,9 @@ impl Manager {
|
||||
|
||||
#[inline]
|
||||
pub fn hovered(&self) -> Option<&File> { self.tabs.active().current.hovered.as_ref() }
|
||||
|
||||
#[inline]
|
||||
pub fn selected(&self) -> Vec<&File> {
|
||||
self.current().selected().or_else(|| self.hovered().map(|h| vec![h])).unwrap_or_default()
|
||||
}
|
||||
}
|
||||
|
@ -41,9 +41,10 @@ impl Process {
|
||||
trace!("Failed to spawn {}: {e}", task.cmd);
|
||||
}
|
||||
}
|
||||
|
||||
emit!(Stop(false)).await;
|
||||
return Ok(());
|
||||
|
||||
self.sch.send(TaskOp::Adv(task.id, 1, 0))?;
|
||||
return self.done(task.id);
|
||||
}
|
||||
|
||||
self.sch.send(TaskOp::New(task.id, 0))?;
|
||||
|
Loading…
Reference in New Issue
Block a user