aboutsummaryrefslogtreecommitdiffstats
path: root/src/run/builtin.rs
diff options
context:
space:
mode:
Diffstat (limited to 'src/run/builtin.rs')
-rw-r--r--src/run/builtin.rs37
1 files changed, 31 insertions, 6 deletions
diff --git a/src/run/builtin.rs b/src/run/builtin.rs
index cdeeffe..c778794 100644
--- a/src/run/builtin.rs
+++ b/src/run/builtin.rs
@@ -1,10 +1,12 @@
+#![allow(non_camel_case_types)]
+
use std::{fs::OpenOptions, path::PathBuf};
use super::Builtin;
use crate::*;
-pub struct Cd;
-impl Builtin for Cd {
+pub struct cd;
+impl Builtin for cd {
fn name(&self) -> &str {
"cd"
}
@@ -20,8 +22,8 @@ impl Builtin for Cd {
}
}
-pub struct Clear;
-impl Builtin for Clear {
+pub struct clear;
+impl Builtin for clear {
fn name(&self) -> &str {
"clear"
}
@@ -31,8 +33,8 @@ impl Builtin for Clear {
}
/// restart shell
-pub struct Re;
-impl Builtin for Re {
+pub struct re;
+impl Builtin for re {
fn name(&self) -> &str {
"re"
}
@@ -82,3 +84,26 @@ pub const fn sink(name: &'static str, append: bool) -> Sink {
// TODO
// from" => todo!("read from file"),
+
+pub struct from;
+impl Builtin for from {
+ fn name(&self) -> &str {
+ "from"
+ }
+
+ fn io(
+ &self,
+ args: &[BString],
+ _stdin: &mut dyn Read,
+ stdout: &mut dyn Write,
+ ) -> std::io::Result<()> {
+ let Some(path) = args.get(0) else {
+ // TODO exit code
+ return Ok(());
+ };
+ let path = PathBuf::from(OsStr::from_bytes(path));
+ let mut file = OpenOptions::new().read(true).open(path)?;
+ std::io::copy(&mut file, stdout)?;
+ Ok(())
+ }
+}