From fc2043d153bb3b38e0cc7c3ce3bfae621858e0b5 Mon Sep 17 00:00:00 2001 From: Jonas Maier <> Date: Thu, 5 Mar 2026 13:54:50 +0100 Subject: from command and a few cosmetic changes --- src/run/builtin.rs | 37 +++++++++++++++++++++++++++++++------ 1 file changed, 31 insertions(+), 6 deletions(-) (limited to 'src/run/builtin.rs') 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(()) + } +} -- cgit v1.2.3