mirror of
https://github.com/nushell/nushell.git
synced 2025-04-16 17:28:19 +02:00
Add $nu.current-exe variable (#8789)
# Description Part solving #8752 Adds an extra variable to the `nu` table `current-exe` which is the path to the running shell executable. # User-Facing Changes Adds a variable to the `nu` table. # Tests + Formatting Tests and formatting have been run. No new test added # After Submitting I could add documentation for this if wanted Co-authored-by: Jelle Besseling <jelle@bigbridge.nl>
This commit is contained in:
parent
49960beb35
commit
e6b196c141
@ -524,10 +524,11 @@ fn variables_completions() {
|
|||||||
// Test completions for $nu
|
// Test completions for $nu
|
||||||
let suggestions = completer.complete("$nu.", 4);
|
let suggestions = completer.complete("$nu.", 4);
|
||||||
|
|
||||||
assert_eq!(12, suggestions.len());
|
assert_eq!(13, suggestions.len());
|
||||||
|
|
||||||
let expected: Vec<String> = vec![
|
let expected: Vec<String> = vec![
|
||||||
"config-path".into(),
|
"config-path".into(),
|
||||||
|
"current-exe".into(),
|
||||||
"env-path".into(),
|
"env-path".into(),
|
||||||
"history-path".into(),
|
"history-path".into(),
|
||||||
"home-path".into(),
|
"home-path".into(),
|
||||||
|
@ -42,6 +42,8 @@ impl LazyRecord for NuVariable {
|
|||||||
cols.push("is-interactive");
|
cols.push("is-interactive");
|
||||||
cols.push("is-login");
|
cols.push("is-login");
|
||||||
|
|
||||||
|
cols.push("current-exe");
|
||||||
|
|
||||||
cols
|
cols
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -213,6 +215,19 @@ impl LazyRecord for NuVariable {
|
|||||||
val: self.engine_state.get_startup_time(),
|
val: self.engine_state.get_startup_time(),
|
||||||
span: self.span(),
|
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}'")),
|
_ => err(&format!("Could not find column '{column}'")),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user