source config from $NU_CONFIG_DIR if it exists (#3883)

This commit is contained in:
soumil-07 2021-08-06 22:17:11 +05:30 committed by GitHub
parent ba483155d7
commit 6646daab45
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -20,6 +20,7 @@ use nu_protocol::{
Value,
};
use nu_source::{SpannedItem, Tag, TaggedItem};
use std::env::var;
use std::fs::{self, OpenOptions};
use std::io;
use std::path::{Path, PathBuf};
@ -168,7 +169,9 @@ pub fn config_path() -> Result<PathBuf, ShellError> {
let dir = ProjectDirs::from("org", "nushell", "nu")
.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| {
ShellError::untagged_runtime_error(&format!("Couldn't create {} path:\n{}", "config", err))
})?;