source config from $NU_CONFIG_DIR if it exists (#3883)
This commit is contained in:
parent
ba483155d7
commit
6646daab45
|
@ -20,6 +20,7 @@ use nu_protocol::{
|
||||||
Value,
|
Value,
|
||||||
};
|
};
|
||||||
use nu_source::{SpannedItem, Tag, TaggedItem};
|
use nu_source::{SpannedItem, Tag, TaggedItem};
|
||||||
|
use std::env::var;
|
||||||
use std::fs::{self, OpenOptions};
|
use std::fs::{self, OpenOptions};
|
||||||
use std::io;
|
use std::io;
|
||||||
use std::path::{Path, PathBuf};
|
use std::path::{Path, PathBuf};
|
||||||
|
@ -168,7 +169,9 @@ pub fn config_path() -> Result<PathBuf, ShellError> {
|
||||||
|
|
||||||
let dir = ProjectDirs::from("org", "nushell", "nu")
|
let dir = ProjectDirs::from("org", "nushell", "nu")
|
||||||
.ok_or_else(|| ShellError::untagged_runtime_error("Couldn't find project directory"))?;
|
.ok_or_else(|| ShellError::untagged_runtime_error("Couldn't find project directory"))?;
|
||||||
let path = ProjectDirs::config_dir(&dir).to_owned();
|
let path = var("NU_CONFIG_DIR").map_or(ProjectDirs::config_dir(&dir).to_owned(), |path| {
|
||||||
|
PathBuf::from(path)
|
||||||
|
});
|
||||||
std::fs::create_dir_all(&path).map_err(|err| {
|
std::fs::create_dir_all(&path).map_err(|err| {
|
||||||
ShellError::untagged_runtime_error(&format!("Couldn't create {} path:\n{}", "config", err))
|
ShellError::untagged_runtime_error(&format!("Couldn't create {} path:\n{}", "config", err))
|
||||||
})?;
|
})?;
|
||||||
|
|
Loading…
Reference in New Issue
Block a user