aboutsummaryrefslogtreecommitdiff
path: root/src/builtins.rs
diff options
context:
space:
mode:
Diffstat (limited to 'src/builtins.rs')
-rw-r--r--src/builtins.rs8
1 files changed, 7 insertions, 1 deletions
diff --git a/src/builtins.rs b/src/builtins.rs
index 4ef2416..b81c4ba 100644
--- a/src/builtins.rs
+++ b/src/builtins.rs
@@ -2,9 +2,15 @@ use std::path::Path;
pub fn cd(args: std::str::SplitWhitespace) -> std::path::PathBuf {
let new_dir = args.peekable().peek().map_or("/", |x| *x);
- let root = Path::new(new_dir);
+
+ let root = match std::fs::canonicalize(Path::new(new_dir)) {
+ Ok(p) => p,
+ Err(_) => Path::new("/").to_path_buf(),
+ };
+
if let Err(e) = std::env::set_current_dir(&root) {
eprintln!("{}", e);
}
+
root.to_path_buf()
}