add cwd to $nu (#469)

* add `cwd` to `$nu`

* oops
This commit is contained in:
Darren Schroeder 2021-12-11 13:38:36 -06:00 committed by GitHub
parent 626b1b99cd
commit c2aa6c708d
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -530,6 +530,18 @@ pub fn eval_variable(
}
}
// since the env var PWD doesn't exist on all platforms
// lets just get the current directory
if let Ok(current_dir) = std::env::current_dir() {
if let Some(cwd) = current_dir.to_str() {
output_cols.push("cwd".into());
output_vals.push(Value::String {
val: cwd.into(),
span,
})
}
}
if let Some(home_path) = nu_path::home_dir() {
if let Some(home_path_str) = home_path.to_str() {
output_cols.push("home-path".into());
@ -540,11 +552,6 @@ pub fn eval_variable(
}
}
if let Ok(cwd) = std::env::var("PWD") {
output_cols.push("pwd".into());
output_vals.push(Value::String { val: cwd, span })
}
Ok(Value::Record {
cols: output_cols,
vals: output_vals,