diff --git a/crates/nu-cli/tests/completions.rs b/crates/nu-cli/tests/completions.rs index 6e44de18f3..ca3c46d51f 100644 --- a/crates/nu-cli/tests/completions.rs +++ b/crates/nu-cli/tests/completions.rs @@ -524,10 +524,11 @@ fn variables_completions() { // Test completions for $nu let suggestions = completer.complete("$nu.", 4); - assert_eq!(12, suggestions.len()); + assert_eq!(13, suggestions.len()); let expected: Vec = vec![ "config-path".into(), + "current-exe".into(), "env-path".into(), "history-path".into(), "home-path".into(), diff --git a/crates/nu-engine/src/nu_variable.rs b/crates/nu-engine/src/nu_variable.rs index e1848dc05b..65d2d4f684 100644 --- a/crates/nu-engine/src/nu_variable.rs +++ b/crates/nu-engine/src/nu_variable.rs @@ -42,6 +42,8 @@ impl LazyRecord for NuVariable { cols.push("is-interactive"); cols.push("is-login"); + cols.push("current-exe"); + cols } @@ -213,6 +215,19 @@ impl LazyRecord for NuVariable { val: self.engine_state.get_startup_time(), span: self.span(), }), + "current-exe" => { + let exe = std::env::current_exe().map_err(|_| { + err("Could not get current executable path") + .expect_err("did not get err from err function") + })?; + + let canon_exe = canonicalize_path(&self.engine_state, &exe); + + Ok(Value::String { + val: canon_exe.to_string_lossy().into(), + span: self.span(), + }) + } _ => err(&format!("Could not find column '{column}'")), } }