aboutsummaryrefslogtreecommitdiffstats
path: root/src/bin
diff options
context:
space:
mode:
Diffstat (limited to 'src/bin')
-rw-r--r--src/bin/aft-ls.rs36
1 files changed, 36 insertions, 0 deletions
diff --git a/src/bin/aft-ls.rs b/src/bin/aft-ls.rs
new file mode 100644
index 0000000..3118c08
--- /dev/null
+++ b/src/bin/aft-ls.rs
@@ -0,0 +1,36 @@
+
+use std::{fs,env,path};
+use std::error::Error;
+use std::os::unix::fs::MetadataExt;
+
+fn main() -> Result<(), Box<dyn Error>> {
+
+ let args: Vec<String> = env::args().collect();
+ let dir = match args.len() {
+ 0 | 1 => path::Path::new("."),
+ _other => path::Path::new(&args[2]),
+ };
+
+ // header is basically a constant
+ print!("\x01");
+ println!("{}\x1D", ["file_name", "size", "mtime"].join("\x1E"));
+ println!("{}\x1D", ["string", "integer+bytes", "datetime"].join("\x1E"));
+ print!("\x02");
+
+ for entry in fs::read_dir(dir)? {
+ let entry = entry?;
+ let metadata = entry.metadata()?;
+ let filename: String = entry.file_name()
+ .into_string()
+ .or_else(|_| Err(format!("Invalid entry")))?;
+ let mtime = chrono::DateTime::<chrono::Utc>::from_utc(
+ chrono::NaiveDateTime::from_timestamp(metadata.mtime(), 0), chrono::Utc);
+ println!("{}\x1D",
+ [
+ filename,
+ metadata.size().to_string(),
+ mtime.to_rfc3339_opts(chrono::SecondsFormat::AutoSi, true),
+ ].join("\x1E"));
+ }
+ Ok(())
+}