From e70327c824d145274430f5f315f464d1d3fda53d Mon Sep 17 00:00:00 2001 From: gennyble Date: Mon, 6 Nov 2023 00:11:09 -0600 Subject: popline :) --- src/main.rs | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) create mode 100644 src/main.rs (limited to 'src/main.rs') diff --git a/src/main.rs b/src/main.rs new file mode 100644 index 0000000..b5994e9 --- /dev/null +++ b/src/main.rs @@ -0,0 +1,23 @@ +fn main() { + if std::env::args().len() != 2 { + eprintln!("usage: popline \n"); + eprintln!("removes the first line of a file and rewrites it to disk without that line"); + std::process::exit(1); + } + + let file = std::path::PathBuf::from(std::env::args().nth(1).unwrap()); + let string = std::fs::read_to_string(&file).unwrap(); + let mut lines = string.lines(); + + let line = match lines.next() { + None => { + std::process::exit(1); + } + Some(line) => line, + }; + + let write = lines.collect::>().join("\n"); + std::fs::write(file, write).unwrap(); + + println!("{line}"); +} -- cgit 1.4.1-3-g733a5