Implemented proper variable scoping
Extracted business logic out of signal handler functions Consolidated state variables into a single struct Implemented var types
This commit is contained in:
@@ -44,7 +44,7 @@ pub fn cd(node: Node, job: &mut JobBldr) -> ShResult<()> {
|
||||
|
||||
env::set_current_dir(new_dir).unwrap();
|
||||
let new_dir = env::current_dir().unwrap();
|
||||
env::set_var("PWD", new_dir);
|
||||
unsafe { env::set_var("PWD", new_dir) };
|
||||
|
||||
state::set_status(0);
|
||||
Ok(())
|
||||
|
||||
@@ -3,8 +3,8 @@ use crate::{
|
||||
libsh::error::ShResult,
|
||||
parse::{NdRule, Node},
|
||||
prelude::*,
|
||||
procio::{borrow_fd, IoStack},
|
||||
state::{self, write_vars},
|
||||
procio::{IoStack, borrow_fd},
|
||||
state::{self, VarFlags, write_vars},
|
||||
};
|
||||
|
||||
use super::setup_builtin;
|
||||
@@ -34,7 +34,7 @@ pub fn export(node: Node, io_stack: &mut IoStack, job: &mut JobBldr) -> ShResult
|
||||
} else {
|
||||
for (arg, _) in argv {
|
||||
if let Some((var, val)) = arg.split_once('=') {
|
||||
write_vars(|v| v.set_var(var, val, true)); // Export an assignment like
|
||||
write_vars(|v| v.set_var(var, val, VarFlags::EXPORT)); // Export an assignment like
|
||||
// 'foo=bar'
|
||||
} else {
|
||||
write_vars(|v| v.export_var(&arg)); // Export an existing variable, if
|
||||
|
||||
@@ -28,7 +28,7 @@ pub fn shift(node: Node, job: &mut JobBldr) -> ShResult<()> {
|
||||
));
|
||||
};
|
||||
for _ in 0..count {
|
||||
write_vars(|v| v.fpop_arg());
|
||||
write_vars(|v| v.cur_scope_mut().fpop_arg());
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user