- fixed 'I' command in normal mode not moving to exact start of line

- Added disown builtin
- Fixed job table not hanging up child processes on exit
- Added target architecture and os to --version output
- Added local builtin for creating variables scoped to functions
This commit is contained in:
2026-02-23 16:10:49 -05:00
parent 1a44a783e0
commit aed0e6fb8c
10 changed files with 205 additions and 17 deletions

View File

@@ -4,7 +4,7 @@ use crate::{
parse::{NdRule, Node},
prelude::*,
procio::{IoStack, borrow_fd},
state::{self, VarFlags, write_vars},
state::{self, VarFlags, read_vars, write_vars},
};
use super::setup_builtin;
@@ -45,3 +45,42 @@ pub fn export(node: Node, io_stack: &mut IoStack, job: &mut JobBldr) -> ShResult
state::set_status(0);
Ok(())
}
pub fn local(node: Node, io_stack: &mut IoStack, job: &mut JobBldr) -> ShResult<()> {
let NdRule::Command {
assignments: _,
argv,
} = node.class
else {
unreachable!()
};
let (argv, _guard) = setup_builtin(argv, job, Some((io_stack, node.redirs)))?;
if argv.is_empty() {
// Display the local variables
let vars_output = read_vars(|v| {
let mut vars = v.flatten_vars()
.into_iter()
.map(|(k, v)| format!("{}={}", k, v))
.collect::<Vec<String>>();
vars.sort();
let mut vars_joined = vars.join("\n");
vars_joined.push('\n');
vars_joined
});
let stdout = borrow_fd(STDOUT_FILENO);
write(stdout, vars_output.as_bytes())?; // Write it
} else {
for (arg, _) in argv {
if let Some((var, val)) = arg.split_once('=') {
write_vars(|v| v.set_var(var, val, VarFlags::LOCAL));
} else {
write_vars(|v| v.set_var(&arg, "", VarFlags::LOCAL)); // Create an uninitialized local variable
}
}
}
state::set_status(0);
Ok(())
}