diff options
author | Jesse Luehrs <doy@tozt.net> | 2022-01-17 00:11:52 -0500 |
---|---|---|
committer | Jesse Luehrs <doy@tozt.net> | 2022-01-17 00:22:16 -0500 |
commit | 296fa4ce873c158b8c87d21db3e566c8ae365504 (patch) | |
tree | 853fdd6ff652c4be9d94830b9ee615a8ac4f8784 /src/env.rs | |
parent | e7d8a9f7d234cb2b8a6691c5a2e33f2b18776a3d (diff) | |
download | nbsh-296fa4ce873c158b8c87d21db3e566c8ae365504.tar.gz nbsh-296fa4ce873c158b8c87d21db3e566c8ae365504.zip |
stop sending environment stuff over a pipe
sending it through the actual environment should be sufficient
Diffstat (limited to 'src/env.rs')
-rw-r--r-- | src/env.rs | 38 |
1 files changed, 22 insertions, 16 deletions
@@ -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<Self> { + 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<u8> { - bincode::serialize(self).unwrap() - } - - pub fn from_bytes(bytes: &[u8]) -> Self { - bincode::deserialize(bytes).unwrap() - } - fn special_var(&self, k: &str) -> Option<String> { 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()), + ] + } } |