Remove uses of NUSHELL_FOLDER
This commit is contained in:
parent
9d24c5efd4
commit
75dc8a6ed1
|
@ -16,15 +16,8 @@ const PLUGIN_FILE: &str = "plugin.msgpackz";
|
||||||
#[cfg(feature = "plugin")]
|
#[cfg(feature = "plugin")]
|
||||||
const OLD_PLUGIN_FILE: &str = "plugin.nu";
|
const OLD_PLUGIN_FILE: &str = "plugin.nu";
|
||||||
|
|
||||||
const HISTORY_FILE_TXT: &str = "history.txt";
|
|
||||||
const HISTORY_FILE_SQLITE: &str = "history.sqlite3";
|
|
||||||
|
|
||||||
#[cfg(feature = "plugin")]
|
#[cfg(feature = "plugin")]
|
||||||
pub fn read_plugin_file(
|
pub fn read_plugin_file(engine_state: &mut EngineState, plugin_file: Option<Spanned<String>>) {
|
||||||
engine_state: &mut EngineState,
|
|
||||||
plugin_file: Option<Spanned<String>>,
|
|
||||||
storage_path: &str,
|
|
||||||
) {
|
|
||||||
use nu_protocol::ShellError;
|
use nu_protocol::ShellError;
|
||||||
use std::path::Path;
|
use std::path::Path;
|
||||||
|
|
||||||
|
@ -52,7 +45,7 @@ pub fn read_plugin_file(
|
||||||
let mut start_time = std::time::Instant::now();
|
let mut start_time = std::time::Instant::now();
|
||||||
// Reading signatures from plugin registry file
|
// Reading signatures from plugin registry file
|
||||||
// The plugin.msgpackz file stores the parsed signature collected from each registered plugin
|
// The plugin.msgpackz file stores the parsed signature collected from each registered plugin
|
||||||
add_plugin_file(engine_state, plugin_file.clone(), storage_path);
|
add_plugin_file(engine_state, plugin_file.clone());
|
||||||
perf!(
|
perf!(
|
||||||
"add plugin file to engine_state",
|
"add plugin file to engine_state",
|
||||||
start_time,
|
start_time,
|
||||||
|
@ -70,8 +63,7 @@ pub fn read_plugin_file(
|
||||||
log::warn!("Plugin file not found: {}", plugin_path.display());
|
log::warn!("Plugin file not found: {}", plugin_path.display());
|
||||||
|
|
||||||
// Try migration of an old plugin file if this wasn't a custom plugin file
|
// Try migration of an old plugin file if this wasn't a custom plugin file
|
||||||
if plugin_file.is_none() && migrate_old_plugin_file(engine_state, storage_path)
|
if plugin_file.is_none() && migrate_old_plugin_file(engine_state) {
|
||||||
{
|
|
||||||
let Ok(file) = std::fs::File::open(&plugin_path) else {
|
let Ok(file) = std::fs::File::open(&plugin_path) else {
|
||||||
log::warn!("Failed to load newly migrated plugin file");
|
log::warn!("Failed to load newly migrated plugin file");
|
||||||
return;
|
return;
|
||||||
|
@ -159,11 +151,7 @@ pub fn read_plugin_file(
|
||||||
}
|
}
|
||||||
|
|
||||||
#[cfg(feature = "plugin")]
|
#[cfg(feature = "plugin")]
|
||||||
pub fn add_plugin_file(
|
pub fn add_plugin_file(engine_state: &mut EngineState, plugin_file: Option<Spanned<String>>) {
|
||||||
engine_state: &mut EngineState,
|
|
||||||
plugin_file: Option<Spanned<String>>,
|
|
||||||
storage_path: &str,
|
|
||||||
) {
|
|
||||||
use std::path::Path;
|
use std::path::Path;
|
||||||
|
|
||||||
let working_set = StateWorkingSet::new(engine_state);
|
let working_set = StateWorkingSet::new(engine_state);
|
||||||
|
@ -189,9 +177,8 @@ pub fn add_plugin_file(
|
||||||
),
|
),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
} else if let Some(mut plugin_path) = nu_path::config_dir() {
|
} else if let Some(plugin_path) = nu_path::nu_config_dir() {
|
||||||
// Path to store plugins signatures
|
// Path to store plugins signatures
|
||||||
plugin_path.push(storage_path);
|
|
||||||
let mut plugin_path =
|
let mut plugin_path =
|
||||||
canonicalize_with(&plugin_path, &cwd).unwrap_or(plugin_path.into());
|
canonicalize_with(&plugin_path, &cwd).unwrap_or(plugin_path.into());
|
||||||
plugin_path.push(PLUGIN_FILE);
|
plugin_path.push(PLUGIN_FILE);
|
||||||
|
@ -243,16 +230,13 @@ pub fn eval_config_contents(
|
||||||
|
|
||||||
pub(crate) fn get_history_path(mode: HistoryFileFormat) -> Option<PathBuf> {
|
pub(crate) fn get_history_path(mode: HistoryFileFormat) -> Option<PathBuf> {
|
||||||
nu_path::nu_config_dir().map(|mut history_path| {
|
nu_path::nu_config_dir().map(|mut history_path| {
|
||||||
history_path.push(match mode {
|
history_path.push(mode.default_file_name());
|
||||||
HistoryFileFormat::PlainText => HISTORY_FILE_TXT,
|
|
||||||
HistoryFileFormat::Sqlite => HISTORY_FILE_SQLITE,
|
|
||||||
});
|
|
||||||
history_path.into()
|
history_path.into()
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
#[cfg(feature = "plugin")]
|
#[cfg(feature = "plugin")]
|
||||||
pub fn migrate_old_plugin_file(engine_state: &EngineState, storage_path: &str) -> bool {
|
pub fn migrate_old_plugin_file(engine_state: &EngineState) -> bool {
|
||||||
use nu_protocol::{
|
use nu_protocol::{
|
||||||
PluginExample, PluginIdentity, PluginRegistryItem, PluginRegistryItemData, PluginSignature,
|
PluginExample, PluginIdentity, PluginRegistryItem, PluginRegistryItemData, PluginSignature,
|
||||||
ShellError,
|
ShellError,
|
||||||
|
@ -265,10 +249,9 @@ pub fn migrate_old_plugin_file(engine_state: &EngineState, storage_path: &str) -
|
||||||
return false;
|
return false;
|
||||||
};
|
};
|
||||||
|
|
||||||
let Some(config_dir) = nu_path::config_dir().and_then(|mut dir| {
|
let Some(config_dir) =
|
||||||
dir.push(storage_path);
|
nu_path::nu_config_dir().and_then(|dir| nu_path::canonicalize_with(dir, &cwd).ok())
|
||||||
nu_path::canonicalize_with(dir, &cwd).ok()
|
else {
|
||||||
}) else {
|
|
||||||
return false;
|
return false;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
@ -1,10 +1,5 @@
|
||||||
use crate::AbsolutePathBuf;
|
use crate::AbsolutePathBuf;
|
||||||
|
|
||||||
#[deprecated(
|
|
||||||
note = "prefer using nu_config_dir() instead of config_dir() joined with NUSHELL_FOLDER"
|
|
||||||
)]
|
|
||||||
pub const NUSHELL_FOLDER: &str = "nushell";
|
|
||||||
|
|
||||||
pub fn home_dir() -> Option<AbsolutePathBuf> {
|
pub fn home_dir() -> Option<AbsolutePathBuf> {
|
||||||
dirs::home_dir().and_then(|home| AbsolutePathBuf::try_from(home).ok())
|
dirs::home_dir().and_then(|home| AbsolutePathBuf::try_from(home).ok())
|
||||||
}
|
}
|
||||||
|
@ -39,8 +34,7 @@ pub fn config_dir() -> Option<AbsolutePathBuf> {
|
||||||
/// Return the nushell config directory.
|
/// Return the nushell config directory.
|
||||||
pub fn nu_config_dir() -> Option<AbsolutePathBuf> {
|
pub fn nu_config_dir() -> Option<AbsolutePathBuf> {
|
||||||
config_dir().map(|mut p| {
|
config_dir().map(|mut p| {
|
||||||
#[allow(deprecated)]
|
p.push("nushell");
|
||||||
p.push(NUSHELL_FOLDER);
|
|
||||||
p
|
p
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
|
@ -15,6 +15,3 @@ pub use helpers::{cache_dir, config_dir, data_dir, home_dir, nu_config_dir};
|
||||||
pub use path::*;
|
pub use path::*;
|
||||||
pub use tilde::expand_tilde;
|
pub use tilde::expand_tilde;
|
||||||
pub use trailing_slash::{has_trailing_slash, strip_trailing_slash};
|
pub use trailing_slash::{has_trailing_slash, strip_trailing_slash};
|
||||||
|
|
||||||
#[allow(deprecated)]
|
|
||||||
pub use helpers::NUSHELL_FOLDER;
|
|
||||||
|
|
|
@ -79,6 +79,16 @@ pub enum HistoryFileFormat {
|
||||||
PlainText,
|
PlainText,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
impl HistoryFileFormat {
|
||||||
|
pub fn default_file_name(self) -> std::path::PathBuf {
|
||||||
|
match self {
|
||||||
|
HistoryFileFormat::PlainText => "history.txt",
|
||||||
|
HistoryFileFormat::Sqlite => "history.sqlite3",
|
||||||
|
}
|
||||||
|
.into()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
impl FromStr for HistoryFileFormat {
|
impl FromStr for HistoryFileFormat {
|
||||||
type Err = &'static str;
|
type Err = &'static str;
|
||||||
|
|
||||||
|
|
|
@ -33,11 +33,8 @@ pub(crate) fn create_nu_constant(engine_state: &EngineState, span: Span) -> Valu
|
||||||
|
|
||||||
let mut record = Record::new();
|
let mut record = Record::new();
|
||||||
|
|
||||||
let config_path = match nu_path::config_dir() {
|
let config_path = match nu_path::nu_config_dir() {
|
||||||
Some(mut path) => {
|
Some(path) => Ok(canonicalize_path(engine_state, path.as_ref())),
|
||||||
path.push("nushell");
|
|
||||||
Ok(canonicalize_path(engine_state, path.as_ref()))
|
|
||||||
}
|
|
||||||
None => Err(Value::error(
|
None => Err(Value::error(
|
||||||
ShellError::ConfigDirNotFound { span: Some(span) },
|
ShellError::ConfigDirNotFound { span: Some(span) },
|
||||||
span,
|
span,
|
||||||
|
|
|
@ -3,8 +3,6 @@ use log::warn;
|
||||||
use nu_cli::read_plugin_file;
|
use nu_cli::read_plugin_file;
|
||||||
use nu_cli::{eval_config_contents, eval_source};
|
use nu_cli::{eval_config_contents, eval_source};
|
||||||
use nu_path::canonicalize_with;
|
use nu_path::canonicalize_with;
|
||||||
#[allow(deprecated)]
|
|
||||||
use nu_path::NUSHELL_FOLDER;
|
|
||||||
use nu_protocol::{
|
use nu_protocol::{
|
||||||
engine::{EngineState, Stack, StateWorkingSet},
|
engine::{EngineState, Stack, StateWorkingSet},
|
||||||
report_error, report_error_new, Config, ParseError, PipelineData, Spanned,
|
report_error, report_error_new, Config, ParseError, PipelineData, Spanned,
|
||||||
|
@ -50,10 +48,7 @@ pub(crate) fn read_config_file(
|
||||||
report_error(&working_set, &e);
|
report_error(&working_set, &e);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} else if let Some(mut config_path) = nu_path::config_dir() {
|
} else if let Some(mut config_path) = nu_path::nu_config_dir() {
|
||||||
#[allow(deprecated)]
|
|
||||||
config_path.push(NUSHELL_FOLDER);
|
|
||||||
|
|
||||||
// Create config directory if it does not exist
|
// Create config directory if it does not exist
|
||||||
if !config_path.exists() {
|
if !config_path.exists() {
|
||||||
if let Err(err) = std::fs::create_dir_all(&config_path) {
|
if let Err(err) = std::fs::create_dir_all(&config_path) {
|
||||||
|
@ -136,9 +131,7 @@ pub(crate) fn read_loginshell_file(engine_state: &mut EngineState, stack: &mut S
|
||||||
);
|
);
|
||||||
|
|
||||||
// read and execute loginshell file if exists
|
// read and execute loginshell file if exists
|
||||||
if let Some(mut config_path) = nu_path::config_dir() {
|
if let Some(mut config_path) = nu_path::nu_config_dir() {
|
||||||
#[allow(deprecated)]
|
|
||||||
config_path.push(NUSHELL_FOLDER);
|
|
||||||
config_path.push(LOGINSHELL_FILE);
|
config_path.push(LOGINSHELL_FILE);
|
||||||
|
|
||||||
warn!("loginshell_file: {}", config_path.display());
|
warn!("loginshell_file: {}", config_path.display());
|
||||||
|
@ -271,8 +264,7 @@ pub(crate) fn setup_config(
|
||||||
);
|
);
|
||||||
let result = catch_unwind(AssertUnwindSafe(|| {
|
let result = catch_unwind(AssertUnwindSafe(|| {
|
||||||
#[cfg(feature = "plugin")]
|
#[cfg(feature = "plugin")]
|
||||||
#[allow(deprecated)]
|
read_plugin_file(engine_state, plugin_file);
|
||||||
read_plugin_file(engine_state, plugin_file, NUSHELL_FOLDER);
|
|
||||||
|
|
||||||
read_config_file(engine_state, stack, env_file, true);
|
read_config_file(engine_state, stack, env_file, true);
|
||||||
read_config_file(engine_state, stack, config_file, false);
|
read_config_file(engine_state, stack, config_file, false);
|
||||||
|
@ -304,9 +296,7 @@ pub(crate) fn set_config_path(
|
||||||
);
|
);
|
||||||
let config_path = match config_file {
|
let config_path = match config_file {
|
||||||
Some(s) => canonicalize_with(&s.item, cwd).ok(),
|
Some(s) => canonicalize_with(&s.item, cwd).ok(),
|
||||||
None => nu_path::config_dir().map(|mut p| {
|
None => nu_path::nu_config_dir().map(|p| {
|
||||||
#[allow(deprecated)]
|
|
||||||
p.push(NUSHELL_FOLDER);
|
|
||||||
let mut p = canonicalize_with(&p, cwd).unwrap_or(p.into());
|
let mut p = canonicalize_with(&p, cwd).unwrap_or(p.into());
|
||||||
p.push(default_config_name);
|
p.push(default_config_name);
|
||||||
canonicalize_with(&p, cwd).unwrap_or(p)
|
canonicalize_with(&p, cwd).unwrap_or(p)
|
||||||
|
|
|
@ -7,8 +7,6 @@ use log::trace;
|
||||||
#[cfg(feature = "plugin")]
|
#[cfg(feature = "plugin")]
|
||||||
use nu_cli::read_plugin_file;
|
use nu_cli::read_plugin_file;
|
||||||
use nu_cli::{evaluate_commands, evaluate_file, evaluate_repl, EvaluateCommandsOpts};
|
use nu_cli::{evaluate_commands, evaluate_file, evaluate_repl, EvaluateCommandsOpts};
|
||||||
#[allow(deprecated)]
|
|
||||||
use nu_path::NUSHELL_FOLDER;
|
|
||||||
use nu_protocol::{
|
use nu_protocol::{
|
||||||
engine::{EngineState, Stack},
|
engine::{EngineState, Stack},
|
||||||
report_error_new, PipelineData, Spanned,
|
report_error_new, PipelineData, Spanned,
|
||||||
|
@ -38,8 +36,7 @@ pub(crate) fn run_commands(
|
||||||
// if the --no-config-file(-n) flag is passed, do not load plugin, env, or config files
|
// if the --no-config-file(-n) flag is passed, do not load plugin, env, or config files
|
||||||
if parsed_nu_cli_args.no_config_file.is_none() {
|
if parsed_nu_cli_args.no_config_file.is_none() {
|
||||||
#[cfg(feature = "plugin")]
|
#[cfg(feature = "plugin")]
|
||||||
#[allow(deprecated)]
|
read_plugin_file(engine_state, parsed_nu_cli_args.plugin_file);
|
||||||
read_plugin_file(engine_state, parsed_nu_cli_args.plugin_file, NUSHELL_FOLDER);
|
|
||||||
|
|
||||||
perf!("read plugins", start_time, use_color);
|
perf!("read plugins", start_time, use_color);
|
||||||
|
|
||||||
|
@ -127,8 +124,7 @@ pub(crate) fn run_file(
|
||||||
if parsed_nu_cli_args.no_config_file.is_none() {
|
if parsed_nu_cli_args.no_config_file.is_none() {
|
||||||
let start_time = std::time::Instant::now();
|
let start_time = std::time::Instant::now();
|
||||||
#[cfg(feature = "plugin")]
|
#[cfg(feature = "plugin")]
|
||||||
#[allow(deprecated)]
|
read_plugin_file(engine_state, parsed_nu_cli_args.plugin_file);
|
||||||
read_plugin_file(engine_state, parsed_nu_cli_args.plugin_file, NUSHELL_FOLDER);
|
|
||||||
perf!("read plugins", start_time, use_color);
|
perf!("read plugins", start_time, use_color);
|
||||||
|
|
||||||
let start_time = std::time::Instant::now();
|
let start_time = std::time::Instant::now();
|
||||||
|
|
Loading…
Reference in New Issue
Block a user