diff options
| author | Jonas Maier <> | 2026-03-05 13:54:50 +0100 |
|---|---|---|
| committer | Jonas Maier <> | 2026-03-05 13:54:50 +0100 |
| commit | fc2043d153bb3b38e0cc7c3ce3bfae621858e0b5 (patch) | |
| tree | 30603a1f2806d5dc408bf3cdc55914f0d2c95169 /src | |
| parent | 727861b38f067b5c162cae2158854e4aec587544 (diff) | |
| download | pish-fc2043d153bb3b38e0cc7c3ce3bfae621858e0b5.tar.gz | |
from command and a few cosmetic changes
Diffstat (limited to 'src')
| -rw-r--r-- | src/run/builtin.rs | 37 | ||||
| -rw-r--r-- | src/run/mod.rs | 8 |
2 files changed, 36 insertions, 9 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(()) + } +} diff --git a/src/run/mod.rs b/src/run/mod.rs index 8eb7ad8..47bf175 100644 --- a/src/run/mod.rs +++ b/src/run/mod.rs @@ -142,6 +142,7 @@ pub fn run(se: &mut Session, cmd: Vec<u8>) { let _ = std::io::stdout().lock().flush(); } +#[allow(unused_variables)] pub trait Builtin: Send + Sync { fn name(&self) -> &str; @@ -160,13 +161,14 @@ pub trait Builtin: Send + Sync { } const BUILTINS: &[&'static dyn Builtin] = &[ - &builtin::Cd, - &builtin::Clear, + &builtin::cd, + &builtin::clear, #[cfg(debug_assertions)] - &builtin::Re, + &builtin::re, &builtin::sink("to", false), &builtin::sink("into", false), &builtin::sink("append", true), + &builtin::from, ]; pub struct CommandDispatch { |
