diff --git a/src/builtins/ls.rs b/src/builtins/ls.rs index 3b921ae..5779b72 100644 --- a/src/builtins/ls.rs +++ b/src/builtins/ls.rs @@ -1,4 +1,8 @@ -use std::{fs::metadata, path::PathBuf, str::FromStr}; +use std::{ + fs::{metadata, Permissions}, + path::PathBuf, + str::FromStr, +}; use chrono::{DateTime, Datelike, Local}; @@ -19,7 +23,7 @@ impl Builtin for Ls { //for entry in entries.by_ref().into_iter() {} println!( - "{} | dir | size | modified | accessed | created |", + "{} | dir | size | modified | accessed | created | readonly |", right_padding(" filename", 20) ); @@ -52,6 +56,8 @@ impl Builtin for Ls { Err(_) => Local::now(), }; + let permissions = metadata.permissions(); + let mut file_type = "unknown"; if metadata.file_type().is_dir() { file_type = "dir" @@ -69,7 +75,8 @@ impl Builtin for Ls { metadata.len(), modified, accessed, - created + created, + permissions ) ); } @@ -106,15 +113,17 @@ fn format_line( modified: DateTime, accessed: DateTime, created: DateTime, + permissions: Permissions, ) -> String { format!( - "{} | {:4} | {:6} | {} | {} | {} |", + "{} | {:4} | {:6} | {} | {} | {} | {} |", right_padding(file_name, max_name_len), file_type, format_filesize(file_size), right_padding(&format_date(modified), 10), right_padding(&format_date(accessed), 10), right_padding(&format_date(created), 10), + right_padding(&permissions.readonly().to_string(), 5), ) }