From c2aa6c708dcfa6032ede35b1c3b2316a0b2e0f98 Mon Sep 17 00:00:00 2001 From: Darren Schroeder <343840+fdncred@users.noreply.github.com> Date: Sat, 11 Dec 2021 13:38:36 -0600 Subject: [PATCH] add `cwd` to `$nu` (#469) * add `cwd` to `$nu` * oops --- crates/nu-engine/src/eval.rs | 17 ++++++++++++----- 1 file changed, 12 insertions(+), 5 deletions(-) diff --git a/crates/nu-engine/src/eval.rs b/crates/nu-engine/src/eval.rs index 000f879f8f..d5353615e0 100644 --- a/crates/nu-engine/src/eval.rs +++ b/crates/nu-engine/src/eval.rs @@ -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,