nushell/src/commands/cd.rs

20 lines
642 B
Rust
Raw Normal View History

2019-05-11 09:00:33 +02:00
use crate::errors::ShellError;
use crate::prelude::*;
2019-05-18 04:53:20 +02:00
use std::env;
2019-05-11 09:00:33 +02:00
pub fn cd(args: CommandArgs) -> Result<OutputStream, ShellError> {
let target = match args.positional.first() {
2019-05-22 09:12:03 +02:00
// TODO: This needs better infra
None => return Err(ShellError::string(format!("cd must take one arg"))),
Some(v) => v.as_string()?.clone(),
};
2019-05-11 09:00:33 +02:00
let cwd = args.env.lock().unwrap().cwd().to_path_buf();
2019-05-12 00:59:57 +02:00
2019-05-22 09:12:03 +02:00
let mut stream = VecDeque::new();
let path = dunce::canonicalize(cwd.join(&target).as_path())?;
let _ = env::set_current_dir(&path);
stream.push_back(ReturnValue::change_cwd(path));
Ok(stream.boxed())
2019-05-11 09:00:33 +02:00
}