diff options
| author | Jonas Maier <> | 2026-03-05 13:14:46 +0100 |
|---|---|---|
| committer | Jonas Maier <> | 2026-03-05 13:14:46 +0100 |
| commit | d19fa2c722943fe09c2001d4e9bc6c27acfdc9d3 (patch) | |
| tree | c7dce9e34f0428d995de9db6ad4e7f73a6ff9dd1 /src/run/builtin.rs | |
| parent | 04b55265cb13c260c8f93ba637e84e184ba83441 (diff) | |
| download | pish-d19fa2c722943fe09c2001d4e9bc6c27acfdc9d3.tar.gz | |
split into builtins
Diffstat (limited to 'src/run/builtin.rs')
| -rw-r--r-- | src/run/builtin.rs | 50 |
1 files changed, 50 insertions, 0 deletions
diff --git a/src/run/builtin.rs b/src/run/builtin.rs index e69de29..feba7f9 100644 --- a/src/run/builtin.rs +++ b/src/run/builtin.rs @@ -0,0 +1,50 @@ +use super::Builtin; +use crate::*; + +pub struct Cd; +impl Builtin for Cd { + fn name(&self) -> &str { + "cd" + } + fn mod_session(&self, _: &mut Session, args: &[BString]) { + let target: &Path = match args.get(0).map(|v| &v[..]) { + Some(b"-") => todo!("prev"), + Some(path) => OsStr::from_bytes(path).as_ref(), + None => todo!("homedir"), + }; + + // TODO: let mod_session builtins return nonzero exit code + let _ = std::env::set_current_dir(target); + } +} + +pub struct Clear; +impl Builtin for Clear { + fn name(&self) -> &str { + "clear" + } + fn mod_session(&self, _: &mut Session, _: &[BString]) { + print!("\x1B[2J\x1B[1;1H"); + } +} + +/// restart shell +pub struct Re; +impl Builtin for Re { + fn name(&self) -> &str { + "re" + } + + fn mod_session(&self, session: &mut Session, _args: &[BString]) { + session.raw.disable(); + let _ = Command::new("cargo").arg("run").status(); + session.raw.disable(); + std::process::exit(0); + } +} + + +// TODO +// from" => todo!("read from file"), +// to" | b"into" => todo!("write into file"), +// append" => todo!("append to file"), |
