summaryrefslogtreecommitdiffstats
path: root/src/runner
diff options
context:
space:
mode:
authorJesse Luehrs <doy@tozt.net>2022-01-17 00:05:00 -0500
committerJesse Luehrs <doy@tozt.net>2022-01-17 00:05:00 -0500
commite7d8a9f7d234cb2b8a6691c5a2e33f2b18776a3d (patch)
tree84eac0ddc63e529275f48071adfdfefd1cdc1c0a /src/runner
parenta537464a915aea2e38c62df041996b8525367bde (diff)
downloadnbsh-e7d8a9f7d234cb2b8a6691c5a2e33f2b18776a3d.tar.gz
nbsh-e7d8a9f7d234cb2b8a6691c5a2e33f2b18776a3d.zip
simplify environment handling
this temporarily breaks cd history, will fix this soon
Diffstat (limited to 'src/runner')
-rw-r--r--src/runner/builtins/mod.rs14
-rw-r--r--src/runner/mod.rs5
2 files changed, 11 insertions, 8 deletions
diff --git a/src/runner/builtins/mod.rs b/src/runner/builtins/mod.rs
index c345a85..f181b45 100644
--- a/src/runner/builtins/mod.rs
+++ b/src/runner/builtins/mod.rs
@@ -67,16 +67,17 @@ fn cd(
if dir.is_empty() {
".".to_string().into()
} else if dir == "-" {
- env.prev_pwd().await
+ env.prev_pwd()
} else {
dir.into()
}
} else {
let dir = env.var("HOME");
- if dir.is_empty() {
+ if let Some(dir) = dir {
+ dir.into()
+ } else {
bail!(cfg, exe, "could not find home directory");
}
- dir.into()
};
let prev = match std::env::current_dir() {
Ok(path) => path,
@@ -98,7 +99,8 @@ fn cd(
dir.display()
);
}
- env.set_prev_pwd(&prev).await;
+ // TODO
+ // env.set_prev_pwd(prev);
async_std::process::ExitStatus::from_raw(0)
}
@@ -255,7 +257,7 @@ fn and(
cfg.setup_command(&mut cmd);
Ok(command::Child::new_wrapped(cmd.spawn(env)?))
} else {
- let status = *env.latest_status();
+ let status = env.latest_status();
Ok(command::Child::new_fut(async move { status }))
}
}
@@ -267,7 +269,7 @@ fn or(
) -> anyhow::Result<command::Child> {
exe.shift();
if env.latest_status().success() {
- let status = *env.latest_status();
+ let status = env.latest_status();
Ok(command::Child::new_fut(async move { status }))
} else {
let mut cmd = crate::runner::Command::new(exe, cfg.io().clone());
diff --git a/src/runner/mod.rs b/src/runner/mod.rs
index a2db255..21ed9c9 100644
--- a/src/runner/mod.rs
+++ b/src/runner/mod.rs
@@ -79,7 +79,7 @@ pub async fn main() -> anyhow::Result<i32> {
let (commands, mut env) = read_data(shell_read).await?;
run_commands(&commands, &mut env, &shell_write).await?;
- let status = *env.latest_status();
+ let status = env.latest_status();
write_event(&shell_write, Event::Exit(env)).await?;
if let Some(signal) = status.signal() {
@@ -216,7 +216,8 @@ async fn run_pipeline(
let (children, pg) = spawn_children(pipeline, env, &io)?;
let status = wait_children(children, pg, env, &io, shell_write).await;
set_foreground_pg(nix::unistd::getpid())?;
- env.update(status)?;
+ env.update()?;
+ env.set_status(status);
Ok(())
}