Add HOME var as default for cd

This commit is contained in:
g1n 2021-07-20 16:43:00 +00:00
parent c66483932d
commit 6dc07fbc90
1 changed files with 4 additions and 3 deletions

View File

@ -10,7 +10,7 @@ fn main(){
loop {
// use the `>` character as the prompt
// need to explicitly flush this to ensure it prints before read_line
print!("> ");
print!("$ ");
stdout().flush().unwrap();
let mut input = String::new();
@ -45,8 +45,9 @@ fn main(){
},
"cd" => {
// default to '/' as new directory if one was not provided
let new_dir = args.peekable().peek().map_or("/", |x| *x);
let root = Path::new(new_dir);
let home_dir = env::var("HOME").unwrap();
let new_dir = args.peekable().peek().map_or(home_dir, |x| (*x).to_string());
let root = Path::new(&new_dir);
if let Err(e) = env::set_current_dir(&root) {
eprintln!("{}", e);
}