mirror of
https://github.com/sxyazi/yazi.git
synced 2026-07-23 07:41:03 +00:00
32 lines
774 B
Rust
32 lines
774 B
Rust
use std::process::Stdio;
|
|
|
|
use anyhow::Result;
|
|
use shared::Url;
|
|
use tokio::{process::Command, sync::oneshot::{self, Receiver}};
|
|
|
|
pub struct ZoxideOpt {
|
|
pub cwd: Url,
|
|
}
|
|
|
|
pub fn zoxide(opt: ZoxideOpt) -> Result<Receiver<Result<Url>>> {
|
|
let child = Command::new("zoxide")
|
|
.args(["query", "-i", "--exclude"])
|
|
.arg(&opt.cwd)
|
|
.kill_on_drop(true)
|
|
.stdout(Stdio::piped())
|
|
.spawn()?;
|
|
|
|
let (tx, rx) = oneshot::channel();
|
|
let cwd = opt.cwd.clone();
|
|
tokio::spawn(async move {
|
|
if let Ok(output) = child.wait_with_output().await {
|
|
let selected = String::from_utf8_lossy(&output.stdout).trim().to_string();
|
|
if !selected.is_empty() {
|
|
tx.send(Ok(Url::new(selected, &cwd))).ok();
|
|
return;
|
|
}
|
|
}
|
|
tx.send(Err(anyhow::anyhow!("No match"))).ok();
|
|
});
|
|
Ok(rx)
|
|
}
|