mirror of
https://github.com/sxyazi/yazi.git
synced 2026-07-25 08:41:05 +00:00
feat: add interactive cd
This commit is contained in:
parent
d198f142e2
commit
598d63ccb9
3 changed files with 22 additions and 3 deletions
|
|
@ -1,4 +1,4 @@
|
||||||
use core::{emit, files::FilesSort, input::InputMode};
|
use core::{files::FilesSort, input::InputMode};
|
||||||
use std::path::PathBuf;
|
use std::path::PathBuf;
|
||||||
|
|
||||||
use config::{keymap::{Control, Exec, Key, KeymapLayer}, manager::SortBy, KEYMAP};
|
use config::{keymap::{Control, Exec, Key, KeymapLayer}, manager::SortBy, KEYMAP};
|
||||||
|
|
@ -67,8 +67,8 @@ impl Executor {
|
||||||
"forward" => cx.manager.active_mut().forward(),
|
"forward" => cx.manager.active_mut().forward(),
|
||||||
"cd" => {
|
"cd" => {
|
||||||
let path = exec.args.get(0).map(PathBuf::from).unwrap_or_default();
|
let path = exec.args.get(0).map(PathBuf::from).unwrap_or_default();
|
||||||
emit!(Cd(path));
|
let interactive = exec.named.contains_key("interactive");
|
||||||
false
|
cx.manager.active_mut().cd_interactive(interactive, path)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Selection
|
// Selection
|
||||||
|
|
|
||||||
|
|
@ -97,6 +97,7 @@ keymap = [
|
||||||
{ on = [ "g", "c" ], exec = "cd ~/.config" },
|
{ on = [ "g", "c" ], exec = "cd ~/.config" },
|
||||||
{ on = [ "g", "d" ], exec = "cd ~/Downloads" },
|
{ on = [ "g", "d" ], exec = "cd ~/Downloads" },
|
||||||
{ on = [ "g", "t" ], exec = "cd /tmp" },
|
{ on = [ "g", "t" ], exec = "cd /tmp" },
|
||||||
|
{ on = [ "g", "<Space>" ], exec = "cd --interactive" },
|
||||||
]
|
]
|
||||||
|
|
||||||
[tasks]
|
[tasks]
|
||||||
|
|
|
||||||
|
|
@ -74,6 +74,24 @@ impl Tab {
|
||||||
true
|
true
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub fn cd_interactive(&mut self, interactive: bool, target: PathBuf) -> bool {
|
||||||
|
if interactive {
|
||||||
|
tokio::spawn(async move {
|
||||||
|
let result = emit!(Input(InputOpt::top("Path:").with_value(target.to_string_lossy())));
|
||||||
|
|
||||||
|
if let Ok(path) = result.await {
|
||||||
|
let path = PathBuf::from(path);
|
||||||
|
emit!(Cd(path));
|
||||||
|
}
|
||||||
|
Ok::<(), Error>(())
|
||||||
|
});
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
emit!(Cd(target));
|
||||||
|
}
|
||||||
|
false
|
||||||
|
}
|
||||||
|
|
||||||
pub async fn cd(&mut self, mut target: PathBuf) -> bool {
|
pub async fn cd(&mut self, mut target: PathBuf) -> bool {
|
||||||
let file = if let Ok(f) = File::from(&target).await {
|
let file = if let Ok(f) = File::from(&target).await {
|
||||||
f
|
f
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue