From 296fa4ce873c158b8c87d21db3e566c8ae365504 Mon Sep 17 00:00:00 2001 From: Jesse Luehrs Date: Mon, 17 Jan 2022 00:11:52 -0500 Subject: stop sending environment stuff over a pipe sending it through the actual environment should be sufficient --- src/env.rs | 38 ++++++++++++++++++++++---------------- 1 file changed, 22 insertions(+), 16 deletions(-) (limited to 'src/env.rs') diff --git a/src/env.rs b/src/env.rs index b612d60..3a6d8b5 100644 --- a/src/env.rs +++ b/src/env.rs @@ -21,14 +21,18 @@ impl Env { Ok(Self::V0(V0 { pwd: pwd.clone(), vars: std::env::vars_os() - .chain( - [ - (__NBSH_IDX.into(), "0".into()), - (__NBSH_LATEST_STATUS.into(), "0".into()), - (__NBSH_PREV_PWD.into(), pwd.into()), - ] - .into_iter(), - ) + .chain(Self::defaults(pwd).into_iter()) + .collect(), + })) + } + + pub fn new_from_env() -> anyhow::Result { + let pwd = std::env::current_dir()?; + Ok(Self::V0(V0 { + pwd: pwd.clone(), + vars: Self::defaults(pwd) + .into_iter() + .chain(std::env::vars_os()) .collect(), })) } @@ -118,14 +122,6 @@ impl Env { Ok(()) } - pub fn as_bytes(&self) -> Vec { - bincode::serialize(self).unwrap() - } - - pub fn from_bytes(bytes: &[u8]) -> Self { - bincode::deserialize(bytes).unwrap() - } - fn special_var(&self, k: &str) -> Option { Some(match k { "$" => crate::info::pid(), @@ -142,4 +138,14 @@ impl Env { _ => return None, }) } + + fn defaults( + pwd: std::path::PathBuf, + ) -> [(std::ffi::OsString, std::ffi::OsString); 3] { + [ + (__NBSH_IDX.into(), "0".into()), + (__NBSH_LATEST_STATUS.into(), "0".into()), + (__NBSH_PREV_PWD.into(), pwd.into()), + ] + } } -- cgit v1.2.3-54-g00ecf