mirror of
https://github.com/sxyazi/yazi.git
synced 2026-07-25 08:41:05 +00:00
feat: cd path auto-completion supports ~ expansion
This commit is contained in:
parent
58e5d2280a
commit
68f5f7faff
2 changed files with 9 additions and 4 deletions
|
|
@ -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()),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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)
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue