feat: add a / to the interactive cd auto-completion candidates (#2777)

Co-authored-by: sxyazi <sxyazi@gmail.com>
This commit is contained in:
Eugene Diachkin 2025-05-19 18:32:36 +03:00 committed by GitHub
parent b6ae5d3ca9
commit 546920e049
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 10 additions and 3 deletions

4
Cargo.lock generated
View file

@ -346,9 +346,9 @@ dependencies = [
[[package]]
name = "cc"
version = "1.2.22"
version = "1.2.23"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "32db95edf998450acc7881c932f94cd9b05c87b4b2599e8bab064753da4acfd1"
checksum = "5f4ac86a9e5bc1e2b3449ab9d7d3a6a405e3d1bb28d7b9be8614f55846ae3766"
dependencies = [
"jobserver",
"libc",

View file

@ -1,4 +1,4 @@
use std::{borrow::Cow, mem, path::{MAIN_SEPARATOR_STR, PathBuf}};
use std::{borrow::Cow, ffi::OsString, mem, path::{MAIN_SEPARATOR_STR, Path, PathBuf}};
use tokio::fs;
use yazi_fs::{CWD, expand_path};
@ -44,6 +44,13 @@ impl Cmp {
tokio::spawn(async move {
let mut dir = fs::read_dir(&parent).await?;
let mut cache = vec![];
// "/" is both a directory separator and the root directory per se
// As there's no parent directory for the FS root, it is a special case
if parent == Path::new("/") {
cache.push(CmpItem { name: OsString::new(), is_dir: true });
}
while let Ok(Some(ent)) = dir.next_entry().await {
if let Ok(ft) = ent.file_type().await {
cache.push(CmpItem { name: ent.file_name(), is_dir: ft.is_dir() });