mirror of
https://github.com/sxyazi/yazi.git
synced 2026-07-25 08:41:05 +00:00
chore: working implementation of --args='...' parameter for fd and rg
This commit is contained in:
parent
faa1d9f37b
commit
ccde30efd4
5 changed files with 25 additions and 3 deletions
1
Cargo.lock
generated
1
Cargo.lock
generated
|
|
@ -2777,6 +2777,7 @@ dependencies = [
|
|||
"regex",
|
||||
"scopeguard",
|
||||
"serde",
|
||||
"shell-words",
|
||||
"tokio",
|
||||
"tokio-stream",
|
||||
"tokio-util",
|
||||
|
|
|
|||
|
|
@ -33,6 +33,7 @@ tokio = { version = "1.37.0", features = [ "full" ] }
|
|||
tokio-stream = "0.1.15"
|
||||
tokio-util = "0.7.10"
|
||||
unicode-width = "0.1.12"
|
||||
shell-words = "1.1.0"
|
||||
|
||||
# Logging
|
||||
tracing = { version = "0.1.40", features = [ "max_level_debug", "release_max_level_warn" ] }
|
||||
|
|
|
|||
|
|
@ -63,11 +63,27 @@ impl Tab {
|
|||
let mut input = InputProxy::show(InputCfg::search(&opt.type_.to_string()));
|
||||
let Some(Ok(subject)) = input.recv().await else { bail!("") };
|
||||
|
||||
let mut arguments = Vec::new();
|
||||
let mut subjects = Vec::new();
|
||||
let words = shell_words::split(&subject)?;
|
||||
for word in words {
|
||||
if word.starts_with("--args=") {
|
||||
let args_string = word.strip_prefix("--args=").unwrap();
|
||||
arguments.extend(shell_words::split(args_string)?);
|
||||
} else {
|
||||
subjects.push(word);
|
||||
}
|
||||
}
|
||||
if subjects.is_empty() {
|
||||
bail!("No search subject found");
|
||||
}
|
||||
let subject = subjects.join(" ");
|
||||
|
||||
cwd = cwd.into_search(subject.clone());
|
||||
let rx = if opt.type_ == OptType::Rg {
|
||||
external::rg(external::RgOpt { cwd: cwd.clone(), hidden, subject })
|
||||
external::rg(external::RgOpt { cwd: cwd.clone(), hidden, subject, args: arguments})
|
||||
} else {
|
||||
external::fd(external::FdOpt { cwd: cwd.clone(), hidden, glob: false, subject })
|
||||
external::fd(external::FdOpt { cwd: cwd.clone(), hidden, glob: false, subject, args: arguments })
|
||||
}?;
|
||||
|
||||
let rx = UnboundedReceiverStream::new(rx).chunks_timeout(1000, Duration::from_millis(300));
|
||||
|
|
|
|||
4
yazi-plugin/src/external/fd.rs
vendored
4
yazi-plugin/src/external/fd.rs
vendored
|
|
@ -1,4 +1,4 @@
|
|||
use std::process::Stdio;
|
||||
use std::{env::args, process::Stdio};
|
||||
|
||||
use anyhow::Result;
|
||||
use tokio::{io::{AsyncBufReadExt, BufReader}, process::Command, sync::mpsc::{self, UnboundedReceiver}};
|
||||
|
|
@ -9,6 +9,7 @@ pub struct FdOpt {
|
|||
pub hidden: bool,
|
||||
pub glob: bool,
|
||||
pub subject: String,
|
||||
pub args: Vec<String>,
|
||||
}
|
||||
|
||||
pub fn fd(opt: FdOpt) -> Result<UnboundedReceiver<File>> {
|
||||
|
|
@ -16,6 +17,7 @@ pub fn fd(opt: FdOpt) -> Result<UnboundedReceiver<File>> {
|
|||
.arg("--base-directory")
|
||||
.arg(&opt.cwd)
|
||||
.args(if opt.hidden { ["--hidden", "--no-ignore"] } else { ["--no-hidden", "--ignore"] })
|
||||
.args(&opt.args)
|
||||
.arg(if opt.glob { "--glob" } else { "--regex" })
|
||||
.arg(&opt.subject)
|
||||
.kill_on_drop(true)
|
||||
|
|
|
|||
2
yazi-plugin/src/external/rg.rs
vendored
2
yazi-plugin/src/external/rg.rs
vendored
|
|
@ -8,6 +8,7 @@ pub struct RgOpt {
|
|||
pub cwd: Url,
|
||||
pub hidden: bool,
|
||||
pub subject: String,
|
||||
pub args: Vec<String>,
|
||||
}
|
||||
|
||||
pub fn rg(opt: RgOpt) -> Result<UnboundedReceiver<File>> {
|
||||
|
|
@ -15,6 +16,7 @@ pub fn rg(opt: RgOpt) -> Result<UnboundedReceiver<File>> {
|
|||
.current_dir(&opt.cwd)
|
||||
.args(["--color=never", "--files-with-matches", "--smart-case"])
|
||||
.args(if opt.hidden { ["--hidden", "--no-ignore"] } else { ["--no-hidden", "--ignore"] })
|
||||
.args(opt.args)
|
||||
.arg(&opt.subject)
|
||||
.kill_on_drop(true)
|
||||
.stdout(Stdio::piped())
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue