From 3eca43c0bb18c23fb4b3986b1dd02e8d81b27860 Mon Sep 17 00:00:00 2001 From: Fernando Herrera Date: Sat, 26 Feb 2022 08:57:51 +0000 Subject: [PATCH] Plugins without file (#4650) * adding plugin location in script * adding plugin location in script --- src/config_files.rs | 19 ++++++++++++++----- src/main.rs | 6 ++++++ 2 files changed, 20 insertions(+), 5 deletions(-) diff --git a/src/config_files.rs b/src/config_files.rs index a4e5262f4..cf2dfb7ba 100644 --- a/src/config_files.rs +++ b/src/config_files.rs @@ -19,12 +19,10 @@ const PLUGIN_FILE: &str = "plugin.nu"; pub(crate) fn read_plugin_file(engine_state: &mut EngineState, stack: &mut Stack) { // Reading signatures from signature file // The plugin.nu file stores the parsed signature collected from each registered plugin - if let Some(mut plugin_path) = nu_path::config_dir() { - // Path to store plugins signatures - plugin_path.push(NUSHELL_FOLDER); - plugin_path.push(PLUGIN_FILE); - engine_state.plugin_signatures = Some(plugin_path.clone()); + add_plugin_file(engine_state); + let plugin_path = engine_state.plugin_signatures.clone(); + if let Some(plugin_path) = plugin_path { let plugin_filename = plugin_path.to_string_lossy().to_owned(); if let Ok(contents) = std::fs::read(&plugin_path) { @@ -37,11 +35,22 @@ pub(crate) fn read_plugin_file(engine_state: &mut EngineState, stack: &mut Stack ); } } + if is_perf_true() { info!("read_plugin_file {}:{}:{}", file!(), line!(), column!()); } } +#[cfg(feature = "plugin")] +pub(crate) fn add_plugin_file(engine_state: &mut EngineState) { + if let Some(mut plugin_path) = nu_path::config_dir() { + // Path to store plugins signatures + plugin_path.push(NUSHELL_FOLDER); + plugin_path.push(PLUGIN_FILE); + engine_state.plugin_signatures = Some(plugin_path.clone()); + } +} + pub(crate) fn read_config_file( engine_state: &mut EngineState, stack: &mut Stack, diff --git a/src/main.rs b/src/main.rs index 962634e30..7d2889672 100644 --- a/src/main.rs +++ b/src/main.rs @@ -191,6 +191,9 @@ fn main() -> Result<()> { } if let Some(commands) = &binary_args.commands { + #[cfg(feature = "plugin")] + config_files::add_plugin_file(&mut engine_state); + let ret_val = commands::evaluate(commands, &init_cwd, &mut engine_state, input); if is_perf_true() { info!("-c command execution {}:{}:{}", file!(), line!(), column!()); @@ -198,6 +201,9 @@ fn main() -> Result<()> { ret_val } else if !script_name.is_empty() && binary_args.interactive_shell.is_none() { + #[cfg(feature = "plugin")] + config_files::add_plugin_file(&mut engine_state); + let ret_val = eval_file::evaluate(script_name, &args_to_script, &mut engine_state, input); if is_perf_true() {