Various additions and improvements

This commit is contained in:
2025-03-15 21:04:45 -04:00
parent 7f21e5baa7
commit 505b968c60
31 changed files with 1421 additions and 341 deletions

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

@@ -0,0 +1,43 @@
use crate::{jobs::{ChildProc, JobBldr}, libsh::error::{ShErr, ShErrKind, ShResult}, parse::{execute::prepare_argv, NdRule, Node}, prelude::*, state::source_file};
pub fn source(node: Node, job: &mut JobBldr) -> ShResult<()> {
let NdRule::Command { assignments: _, argv } = node.class else {
unreachable!()
};
let child_pgid = if let Some(pgid) = job.pgid() {
pgid
} else {
job.set_pgid(Pid::this());
Pid::this()
};
let child = ChildProc::new(Pid::this(), Some("source"), Some(child_pgid))?;
job.push_child(child);
let argv = prepare_argv(argv).into_iter().skip(1);
for (arg,span) in argv {
let path = PathBuf::from(arg);
if !path.exists() {
return Err(
ShErr::full(
ShErrKind::ExecFail,
"source: File not found",
span.into()
)
);
}
if !path.is_file() {
return Err(
ShErr::full(
ShErrKind::ExecFail,
"source: Given path is not a file",
span.into()
)
);
}
source_file(path)?;
}
Ok(())
}