about summary refs log tree commit diff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/main.rs23
1 files changed, 23 insertions, 0 deletions
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 <file>\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::<Vec<&str>>().join("\n");
+	std::fs::write(file, write).unwrap();
+
+	println!("{line}");
+}