Various improvements

This commit is contained in:
2025-03-07 03:36:25 -05:00
parent 3034f6c8d2
commit 90243834ff
15 changed files with 305 additions and 175 deletions

View File

@@ -6,8 +6,9 @@ pub mod jobctl;
pub mod read;
pub mod alias;
pub mod control_flow;
pub mod source;
pub const BUILTINS: [&str;13] = [
pub const BUILTINS: [&str;14] = [
"echo",
"cd",
"pwd",
@@ -21,4 +22,5 @@ pub const BUILTINS: [&str;13] = [
"continue",
"return",
"break",
"source",
];

15
src/builtin/source.rs Normal file
View File

@@ -0,0 +1,15 @@
use crate::prelude::*;
pub fn source(node: Node, shenv: &mut ShEnv) -> ShResult<()> {
let rule = node.into_rule();
if let NdRule::Command { argv, redirs } = rule {
shenv.collect_redirs(redirs);
let mut argv_iter = argv.into_iter().skip(1);
while let Some(arg) = argv_iter.next() {
let arg_raw = arg.as_raw(shenv);
let arg_path = PathBuf::from(arg_raw);
shenv.source_file(arg_path)?;
}
} else { unreachable!() }
Ok(())
}