feat: better cd

This commit is contained in:
♥ Minnie ♥ 2025-06-10 18:40:31 +08:00
parent 2061bb4f74
commit fa47639ef3
Signed by: jasmine
GPG key ID: 8563E358D4E8040E

View file

@ -1,8 +1,17 @@
// Provides Built-In Shell Functions.
pub fn cd(args: &[String]) {
let path = args[0].to_string();
assert!(std::env::set_current_dir(&path).is_ok());
let path = if args.is_empty() {
std::env::var("HOME").unwrap_or_default()
} else {
shellexpand::tilde(&args[0]).to_string()
};
let status = std::env::set_current_dir(&path);
if status.is_err() {
println!("cd: no such file or directory: {}", &path);
}
}
pub fn help() {