diff --git a/yazi-config/preset/keymap.toml b/yazi-config/preset/keymap.toml index af622e9e..981e4c57 100644 --- a/yazi-config/preset/keymap.toml +++ b/yazi-config/preset/keymap.toml @@ -80,7 +80,8 @@ keymap = [ { on = [ "S" ], exec = "search rg", desc = "Search files by content using ripgrep" }, { on = [ "" ], exec = "search none", desc = "Cancel the ongoing search" }, { on = [ "z" ], exec = "jump zoxide", desc = "Jump to a directory using zoxide" }, - { on = [ "Z" ], exec = "jump fzf", desc = "Jump to a directory, or reveal a file using fzf" }, + { on = [ "Z" ], exec = "jump zoxide_interactive", desc = "Jump to a directory using zoxide interactively"}, + # { on = [ " " ], exec = "jump fzf", desc = "Jump to a directory, or reveal a file using fzf" }, # Linemode { on = [ "m", "s" ], exec = "linemode size", desc = "Set linemode to size" }, diff --git a/yazi-config/preset/yazi.toml b/yazi-config/preset/yazi.toml index 789263cc..237c82b6 100644 --- a/yazi-config/preset/yazi.toml +++ b/yazi-config/preset/yazi.toml @@ -178,6 +178,11 @@ quit_title = "{n} task{s} running, sure to quit? (y/N)" quit_origin = "top-center" quit_offset = [ 0, 2, 50, 3 ] +# zoxide +zoxide_title = "Zoxide query" +zoxide_origin = "top-center" +zoxide_offset = [ 0, 2, 50, 3 ] + [select] open_title = "Open with:" open_origin = "hovered" diff --git a/yazi-config/src/popup/input.rs b/yazi-config/src/popup/input.rs index 4b1f9d52..c1551c1e 100644 --- a/yazi-config/src/popup/input.rs +++ b/yazi-config/src/popup/input.rs @@ -59,6 +59,11 @@ pub struct Input { pub quit_title: String, pub quit_origin: Origin, pub quit_offset: Offset, + + // zoxide + pub zoxide_title: String, + pub zoxide_origin: Origin, + pub zoxide_offset: Offset, } impl Default for Input { diff --git a/yazi-config/src/popup/options.rs b/yazi-config/src/popup/options.rs index 2c7e72c6..40d753ff 100644 --- a/yazi-config/src/popup/options.rs +++ b/yazi-config/src/popup/options.rs @@ -126,6 +126,15 @@ impl InputCfg { } } + #[inline] + pub fn zoxide() -> Self { + Self { + title: INPUT.zoxide_title.to_owned(), + position: Position::new(INPUT.zoxide_origin, INPUT.zoxide_offset), + ..Default::default() + } + } + #[inline] pub fn with_value(mut self, value: impl Into) -> Self { self.value = value.into(); diff --git a/yazi-core/src/tab/commands/jump.rs b/yazi-core/src/tab/commands/jump.rs index c282205d..f9b1d2e8 100644 --- a/yazi-core/src/tab/commands/jump.rs +++ b/yazi-core/src/tab/commands/jump.rs @@ -1,7 +1,10 @@ +use anyhow::anyhow; +use yazi_config::popup::InputCfg; use yazi_plugin::external::{self, FzfOpt, ZoxideOpt}; use yazi_scheduler::{Scheduler, BLOCKER}; use yazi_shared::{event::Cmd, fs::ends_with_slash, Defer}; +use crate::input::Input; use crate::tab::Tab; pub struct Opt { @@ -13,6 +16,7 @@ pub enum OptType { None, Fzf, Zoxide, + ZoxideInteractive, } impl From for Opt { @@ -21,6 +25,7 @@ impl From for Opt { type_: match c.args.first().map(|s| s.as_str()) { Some("fzf") => OptType::Fzf, Some("zoxide") => OptType::Zoxide, + Some("zoxide_interactive") => OptType::ZoxideInteractive, _ => OptType::None, }, } @@ -33,17 +38,28 @@ impl Tab { if opt.type_ == OptType::None { return; } - let cwd = self.current.cwd.clone(); + tokio::spawn(async move { let _guard = BLOCKER.acquire().await.unwrap(); let _defer = Defer::new(Scheduler::app_resume); Scheduler::app_stop().await; - let result = if opt.type_ == OptType::Fzf { - external::fzf(FzfOpt { cwd }).await - } else { - external::zoxide(ZoxideOpt { cwd }).await + let result = match opt.type_ { + OptType::Fzf => external::fzf(FzfOpt { cwd }).await, + OptType::ZoxideInteractive => external::zoxide(ZoxideOpt { cwd, query: None }).await, + OptType::Zoxide => { + println!("Showing input"); + let mut result = Input::_show(InputCfg::zoxide()); + + if let Some(Ok(input)) = result.recv().await { + println!("Got input: {input}"); + external::zoxide(ZoxideOpt { cwd, query: Some(input) }).await + } else { + Err(anyhow!("")) + } + } + _ => Err(anyhow!("")) }; let Ok(url) = result else { diff --git a/yazi-plugin/src/external/zoxide.rs b/yazi-plugin/src/external/zoxide.rs index 23d4ff2c..2781da42 100644 --- a/yazi-plugin/src/external/zoxide.rs +++ b/yazi-plugin/src/external/zoxide.rs @@ -6,12 +6,14 @@ use yazi_shared::fs::Url; pub struct ZoxideOpt { pub cwd: Url, + pub query: Option, } pub async fn zoxide(opt: ZoxideOpt) -> Result { let child = Command::new("zoxide") - .args(["query", "-i", "--exclude"]) + .args(["query", "--exclude"]) .arg(&opt.cwd) + .arg(if let Some(query) = &opt.query { query } else { "--interactive" }) .kill_on_drop(true) .stdout(Stdio::piped()) .spawn()?;