diff options
author | Jesse Luehrs <doy@tozt.net> | 2022-01-08 00:46:49 -0500 |
---|---|---|
committer | Jesse Luehrs <doy@tozt.net> | 2022-01-08 00:46:49 -0500 |
commit | 9f7e4412f334dca01f19d275af6a3eaa5b449dba (patch) | |
tree | 1ad97ad7184c62ab8ad6c285f06360d251e6c49f /src/env.rs | |
parent | 489fd0db1bf7f1de31a043e315179e83b77921aa (diff) | |
download | nbsh-9f7e4412f334dca01f19d275af6a3eaa5b449dba.tar.gz nbsh-9f7e4412f334dca01f19d275af6a3eaa5b449dba.zip |
implement environment variables
Diffstat (limited to 'src/env.rs')
-rw-r--r-- | src/env.rs | 15 |
1 files changed, 15 insertions, 0 deletions
@@ -17,6 +17,7 @@ pub struct V0 { )] latest_status: async_std::process::ExitStatus, pwd: std::path::PathBuf, + vars: std::collections::HashMap<std::ffi::OsString, std::ffi::OsString>, } impl Env { @@ -26,6 +27,7 @@ impl Env { idx: 0, latest_status: std::process::ExitStatus::from_raw(0), pwd: std::env::current_dir().unwrap(), + vars: std::env::vars_os().collect(), }) } @@ -83,10 +85,23 @@ impl Env { } } + pub fn var(&self, k: &str) -> String { + match self { + Self::V0(env) => { + env.vars.get(std::ffi::OsStr::new(k)).map_or_else( + || "".to_string(), + |v| v.to_str().unwrap().to_string(), + ) + } + } + } + pub fn apply(&self, cmd: &mut pty_process::Command) { match self { Self::V0(env) => { cmd.current_dir(&env.pwd); + cmd.env_clear(); + cmd.envs(env.vars.iter()); } } } |