summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJesse Luehrs <doy@tozt.net>2022-01-16 22:50:22 -0500
committerJesse Luehrs <doy@tozt.net>2022-01-16 22:50:22 -0500
commita537464a915aea2e38c62df041996b8525367bde (patch)
tree37f7a13167d1ea4f655c3a695c662abd0febe525
parentb66e1f99c30625988ec489f278e449a840bb3754 (diff)
downloadnbsh-a537464a915aea2e38c62df041996b8525367bde.tar.gz
nbsh-a537464a915aea2e38c62df041996b8525367bde.zip
move default environment variable setting to shell initialization
-rw-r--r--src/env.rs17
-rw-r--r--src/shell/mod.rs5
2 files changed, 13 insertions, 9 deletions
diff --git a/src/env.rs b/src/env.rs
index bf6cb6c..981d8fc 100644
--- a/src/env.rs
+++ b/src/env.rs
@@ -26,19 +26,13 @@ pub struct V0 {
impl Env {
pub fn new() -> anyhow::Result<Self> {
- let mut vars: std::collections::HashMap<
- std::ffi::OsString,
- std::ffi::OsString,
- > = std::env::vars_os().collect();
- vars.insert("SHELL".into(), std::env::current_exe()?.into());
- vars.insert("TERM".into(), "screen".into());
let pwd = std::env::current_dir()?;
Ok(Self::V0(V0 {
idx: 0,
latest_status: std::process::ExitStatus::from_raw(0),
pwd: pwd.clone(),
prev_pwd: crate::mutex::new(pwd),
- vars,
+ vars: std::env::vars_os().collect(),
}))
}
@@ -85,7 +79,14 @@ impl Env {
}
}
- pub fn set_var<T: Into<std::ffi::OsString>>(&mut self, k: T, v: T) {
+ pub fn set_var<
+ K: Into<std::ffi::OsString>,
+ V: Into<std::ffi::OsString>,
+ >(
+ &mut self,
+ k: K,
+ v: V,
+ ) {
match self {
Self::V0(env) => {
env.vars.insert(k.into(), v.into());
diff --git a/src/shell/mod.rs b/src/shell/mod.rs
index 0547bae..8343b0e 100644
--- a/src/shell/mod.rs
+++ b/src/shell/mod.rs
@@ -212,10 +212,13 @@ pub struct Shell {
impl Shell {
pub fn new(offset: time::UtcOffset) -> anyhow::Result<Self> {
+ let mut env = Env::new()?;
+ env.set_var("SHELL", std::env::current_exe()?);
+ env.set_var("TERM", "screen");
Ok(Self {
readline: readline::Readline::new(),
history: history::History::new(),
- env: Env::new()?,
+ env,
git: None,
focus: Focus::Readline,
scene: Scene::Readline,