summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/compose.rs14
-rw-r--r--src/main.rs2
-rw-r--r--src/poem/anthology/cd.rs9
3 files changed, 20 insertions, 5 deletions
diff --git a/src/compose.rs b/src/compose.rs
index 3d2a2db..c90f470 100644
--- a/src/compose.rs
+++ b/src/compose.rs
@@ -1,6 +1,7 @@
use crate::poem::{read::Readable, recite::Reciteable, Poem};
pub mod environment;
pub use environment::Environment;
+use std::env;
use std::fs;
use std::path::PathBuf;
@@ -18,8 +19,17 @@ pub fn env() -> Environment {
};
// User defined rc file in ~
- let mut local_rc = PathBuf::from(env!("HOME"));
- local_rc.push(".dwvshrc");
+ let local_rc = match env::var("HOME") {
+ Ok(val) => {
+ let mut rc = PathBuf::from(val);
+ rc.push(".dwvshrc");
+ rc
+ }
+ Err(_) => {
+ eprintln!("dwvsh: unknown home, falling back to /etc");
+ PathBuf::from(&global_rc)
+ }
+ };
// Read, read, and recite
rrr(global_rc, &mut env);
diff --git a/src/main.rs b/src/main.rs
index 898d19e..c17f959 100644
--- a/src/main.rs
+++ b/src/main.rs
@@ -80,8 +80,6 @@ fn repl(prompt: &str, at_prompt: &mut Arc<Mutex<bool>>, env: &mut Environment) {
/// Shell setup and entry
fn main() {
// Compose the environment for dwvsh
- // TODO: All instances of `env!("HOME")` need to be changed to use env::var
- // TODO: Will probably need to set $HOME in dwv{profile,login} via passwd
let mut env = compose::env();
// Set the prompt
diff --git a/src/poem/anthology/cd.rs b/src/poem/anthology/cd.rs
index 3b48f60..d3a1998 100644
--- a/src/poem/anthology/cd.rs
+++ b/src/poem/anthology/cd.rs
@@ -1,9 +1,16 @@
use crate::poem::Verse;
+use std::env;
pub fn incant(verse: &Verse) -> i32 {
let path = match verse.clause() {
Some(path) => path[0].to_string(),
- None => env!("HOME").to_string(),
+ None => match env::var("HOME") {
+ Ok(val) => val,
+ Err(_) => {
+ eprintln!("cd: unknown home, staying in pwd");
+ return 1;
+ }
+ },
};
match std::env::set_current_dir(&path) {