Skip to content

Commit

Permalink
fix: display actual dir name instead of the dot at the top
Browse files Browse the repository at this point in the history
  • Loading branch information
Z1xus committed Jan 3, 2025
1 parent 7ae5dc6 commit 4b406c9
Showing 1 changed file with 18 additions and 4 deletions.
22 changes: 18 additions & 4 deletions src/list_directories.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
use glob::Pattern;
use std::{fs, io, path::PathBuf};
use std::{
fs, io,
path::{Path, PathBuf},
};

const RESET: &str = "\x1b[0m";
const HIDDEN: &str = "\x1b[2m"; // Dim
Expand Down Expand Up @@ -98,6 +101,20 @@ pub fn list_directories(
dirs_only: bool,
) -> io::Result<()> {
if current_depth <= max_depth {
if current_depth == 0 {
let root_name = if path == Path::new(".") {
std::env::current_dir()
.ok()
.and_then(|p| p.file_name().map(|n| n.to_string_lossy().into_owned()))
.unwrap_or_else(|| ".".to_string())
} else {
path.file_name()
.map(|n| n.to_string_lossy().into_owned())
.unwrap_or_else(|| ".".to_string())
};
println!("{}{}/", DIR, root_name);
}

let mut entries: Vec<_> = fs::read_dir(path)?
.filter_map(|e| e.ok())
.filter(|entry| {
Expand Down Expand Up @@ -144,9 +161,6 @@ pub fn list_directories(
let suffix = if path.is_dir() { "/" } else { "" };
let style = get_file_style(entry);

if current_depth == 0 && i == 0 {
println!(".");
}
println!("{}{}{}{}{}{}", prefix, symbol, style, name, suffix, RESET);

if path.is_dir() {
Expand Down

0 comments on commit 4b406c9

Please sign in to comment.