blob: b81c4bad276f5e38d4349bcb2af8d4aa26314fe0 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
|
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()
}
|