Change NU_LIB_DIRS not to depend on $nu.config-path (#8887)

This commit is contained in:
goldfish 2023-04-15 05:16:00 +09:00 committed by GitHub
parent 9b35d59023
commit 45d33e70db
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 22 additions and 4 deletions

View File

@ -524,11 +524,12 @@ 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!(13, suggestions.len()); assert_eq!(14, suggestions.len());
let expected: Vec<String> = vec![ let expected: Vec<String> = vec![
"config-path".into(), "config-path".into(),
"current-exe".into(), "current-exe".into(),
"default-config-dir".into(),
"env-path".into(), "env-path".into(),
"history-path".into(), "history-path".into(),
"home-path".into(), "home-path".into(),

View File

@ -25,7 +25,13 @@ pub struct NuVariable {
impl LazyRecord for NuVariable { impl LazyRecord for NuVariable {
fn column_names(&self) -> Vec<&'static str> { fn column_names(&self) -> Vec<&'static str> {
let mut cols = vec!["config-path", "env-path", "history-path", "loginshell-path"]; let mut cols = vec![
"default-config-dir",
"config-path",
"env-path",
"history-path",
"loginshell-path",
];
#[cfg(feature = "plugin")] #[cfg(feature = "plugin")]
if self.engine_state.plugin_signatures.is_some() { if self.engine_state.plugin_signatures.is_some() {
@ -70,6 +76,17 @@ impl LazyRecord for NuVariable {
} }
match column { match column {
"default-config-dir" => {
if let Some(mut path) = nu_path::config_dir() {
path.push("nushell");
Ok(Value::String {
val: path.to_string_lossy().to_string(),
span: self.span,
})
} else {
err("Could not get config directory")
}
}
"config-path" => { "config-path" => {
if let Some(path) = self.engine_state.get_config_path("config-path") { if let Some(path) = self.engine_state.get_config_path("config-path") {
let canon_config_path = canonicalize_path(&self.engine_state, path); let canon_config_path = canonicalize_path(&self.engine_state, path);

View File

@ -72,14 +72,14 @@ let-env ENV_CONVERSIONS = {
# #
# By default, <nushell-config-dir>/scripts is added # By default, <nushell-config-dir>/scripts is added
let-env NU_LIB_DIRS = [ let-env NU_LIB_DIRS = [
($nu.config-path | path dirname | path join 'scripts') ($nu.default-config-dir | path join 'scripts')
] ]
# Directories to search for plugin binaries when calling register # Directories to search for plugin binaries when calling register
# #
# By default, <nushell-config-dir>/plugins is added # By default, <nushell-config-dir>/plugins is added
let-env NU_PLUGIN_DIRS = [ let-env NU_PLUGIN_DIRS = [
($nu.config-path | path dirname | path join 'plugins') ($nu.default-config-dir | path join 'plugins')
] ]
# To add entries to PATH (on Windows you might use Path), you can use the following pattern: # To add entries to PATH (on Windows you might use Path), you can use the following pattern: