about summary refs log tree commit diff
path: root/src/main.rs
diff options
context:
space:
mode:
authorgennyble <gen@nyble.dev>2023-11-06 00:11:09 -0600
committergennyble <gen@nyble.dev>2023-11-06 00:11:09 -0600
commite70327c824d145274430f5f315f464d1d3fda53d (patch)
tree4503f26ebdc7c2e5fd642f0ce1d13ae3418e2143 /src/main.rs
downloadpopline-e70327c824d145274430f5f315f464d1d3fda53d.tar.gz
popline-e70327c824d145274430f5f315f464d1d3fda53d.zip
popline :)
Diffstat (limited to 'src/main.rs')
-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}");
+}