From bdf1b21bb050ef157b7b98fd027b8b1c5369f84a Mon Sep 17 00:00:00 2001 From: Guilleag01 Date: Fri, 10 Nov 2023 08:07:04 +0100 Subject: [PATCH] Symlinks now show the target they are pointing to --- README.md | 2 +- src/element.rs | 27 ++++++++++++++++++++------- src/out/list.rs | 2 +- 3 files changed, 22 insertions(+), 9 deletions(-) diff --git a/README.md b/README.md index f5b7661..1a16313 100644 --- a/README.md +++ b/README.md @@ -1,2 +1,2 @@ # lsplus -A better ls for linux systems, writter in rust +A better ls for linux systems, written in rust diff --git a/src/element.rs b/src/element.rs index 125fe4a..8a3d084 100644 --- a/src/element.rs +++ b/src/element.rs @@ -1,4 +1,10 @@ -use std::{fmt::Display, fs, os::unix::prelude::FileTypeExt, path::Path, time::SystemTime}; +use std::{ + fmt::Display, + fs::{self, read_link}, + os::unix::prelude::FileTypeExt, + path::Path, + time::SystemTime, +}; use crate::utils::get_icon_file_type; @@ -44,15 +50,22 @@ impl Element { t = TypeOfFile::File; } + let mut name = path_built + .file_name() + .unwrap() + .to_str() + .unwrap() + .to_string(); + + if symlink_metadata.is_symlink() { + name.push_str(" -> "); + name.push_str(read_link(path_built).unwrap().to_str().unwrap()) + } + Self { path: path_str.to_string(), file_type: t, - name: path_built - .file_name() - .unwrap() - .to_str() - .unwrap() - .to_string(), + name, perms: metadata.permissions(), size: metadata.len(), creation: metadata.created().unwrap(), diff --git a/src/out/list.rs b/src/out/list.rs index 80c9b43..808cf4d 100644 --- a/src/out/list.rs +++ b/src/out/list.rs @@ -5,7 +5,7 @@ pub fn list(mut elements: Vec) { elements.sort_unstable_by_key(|a: &Element| a.get_name()); let width = term_size::dimensions().unwrap().0; // ╭──────────────╼ File name ╾──────────────┬─╼ Size ╾─┬──╼ Creation ╾──╮ - // │ │ │ │ + // │ some_example_file │ 420.69 G │ 01-01-70 00:00 │ // ╰─────────────────────────────────────────┴──────────┴────────────────╯ let mut name_max_len = 0; for e in &elements {