From e7d8a9f7d234cb2b8a6691c5a2e33f2b18776a3d Mon Sep 17 00:00:00 2001 From: Jesse Luehrs Date: Mon, 17 Jan 2022 00:05:00 -0500 Subject: simplify environment handling this temporarily breaks cd history, will fix this soon --- src/runner/builtins/mod.rs | 14 ++++++++------ src/runner/mod.rs | 5 +++-- 2 files changed, 11 insertions(+), 8 deletions(-) (limited to 'src/runner') 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 { 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 { 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(()) } -- cgit v1.2.3-54-g00ecf