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 = 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() }