From 68f5f7faffbdae578bbe29ead60dee0d027d424d Mon Sep 17 00:00:00 2001 From: sxyazi Date: Thu, 23 May 2024 17:03:24 +0800 Subject: [PATCH] feat: `cd` path auto-completion supports `~` expansion --- yazi-core/src/completion/commands/trigger.rs | 7 +++++-- yazi-core/src/input/commands/complete.rs | 6 ++++-- 2 files changed, 9 insertions(+), 4 deletions(-) diff --git a/yazi-core/src/completion/commands/trigger.rs b/yazi-core/src/completion/commands/trigger.rs index 535fc3c7..dd8f213a 100644 --- a/yazi-core/src/completion/commands/trigger.rs +++ b/yazi-core/src/completion/commands/trigger.rs @@ -1,7 +1,7 @@ use std::{mem, path::{MAIN_SEPARATOR, MAIN_SEPARATOR_STR}}; use tokio::fs; -use yazi_shared::{emit, event::{Cmd, Data}, render, Layer}; +use yazi_shared::{emit, event::{Cmd, Data}, fs::expand_path, render, Layer}; use crate::completion::Completion; @@ -74,9 +74,12 @@ impl Completion { #[inline] fn split_path(s: &str) -> (String, String) { + let p = expand_path(s); + let s = p.to_string_lossy(); + match s.rsplit_once(SEPARATOR) { Some((p, c)) => (format!("{p}{}", MAIN_SEPARATOR), c.to_owned()), - None => (".".to_owned(), s.to_owned()), + None => (".".to_owned(), s.into_owned()), } } } diff --git a/yazi-core/src/input/commands/complete.rs b/yazi-core/src/input/commands/complete.rs index 8c3704c1..88d31365 100644 --- a/yazi-core/src/input/commands/complete.rs +++ b/yazi-core/src/input/commands/complete.rs @@ -1,6 +1,6 @@ use std::path::MAIN_SEPARATOR_STR; -use yazi_shared::{event::{Cmd, Data}, render}; +use yazi_shared::{event::{Cmd, Data}, fs::expand_path, render}; use crate::input::Input; @@ -32,7 +32,9 @@ impl Input { } let [before, after] = self.partition(); - let new = if let Some((prefix, _)) = before.rsplit_once(SEPARATOR) { + let before = expand_path(before); + + let new = if let Some((prefix, _)) = before.to_string_lossy().rsplit_once(SEPARATOR) { format!("{prefix}/{}{after}", opt.word).replace(SEPARATOR, MAIN_SEPARATOR_STR) } else { format!("{}{after}", opt.word).replace(SEPARATOR, MAIN_SEPARATOR_STR)