mirror of
https://github.com/nushell/nushell.git
synced 2025-08-15 10:13:13 +02:00
Try again with math-like externals (#4629)
* Try again with math-like externals * clippy 1.59 * clippy 1.59 * clippy 1.59
This commit is contained in:
@ -19,10 +19,6 @@ pub(crate) fn evaluate(
|
||||
// First, set up env vars as strings only
|
||||
gather_parent_env_vars(engine_state);
|
||||
|
||||
// Make a note of the exceptions we see for externals that look like math expressions
|
||||
let exceptions = crate::utils::external_exceptions();
|
||||
engine_state.external_exceptions = exceptions;
|
||||
|
||||
// Run a command (or commands) given to us by the user
|
||||
let (block, delta) = {
|
||||
let mut working_set = StateWorkingSet::new(engine_state);
|
||||
@ -78,6 +74,10 @@ pub(crate) fn evaluate(
|
||||
}
|
||||
};
|
||||
|
||||
// Make a note of the exceptions we see for externals that look like math expressions
|
||||
let exceptions = crate::utils::external_exceptions(engine_state, &stack);
|
||||
engine_state.external_exceptions = exceptions;
|
||||
|
||||
// Merge the delta in case env vars changed in the config
|
||||
match nu_engine::env::current_dir(engine_state, &stack) {
|
||||
Ok(cwd) => {
|
||||
|
@ -22,10 +22,6 @@ pub(crate) fn evaluate(
|
||||
// First, set up env vars as strings only
|
||||
gather_parent_env_vars(engine_state);
|
||||
|
||||
// Make a note of the exceptions we see for externals that look like math expressions
|
||||
let exceptions = crate::utils::external_exceptions();
|
||||
engine_state.external_exceptions = exceptions;
|
||||
|
||||
let mut stack = nu_protocol::engine::Stack::new();
|
||||
|
||||
// Set up our initial config to start from
|
||||
@ -45,6 +41,10 @@ pub(crate) fn evaluate(
|
||||
std::process::exit(1);
|
||||
}
|
||||
|
||||
// Make a note of the exceptions we see for externals that look like math expressions
|
||||
let exceptions = crate::utils::external_exceptions(engine_state, &stack);
|
||||
engine_state.external_exceptions = exceptions;
|
||||
|
||||
let file = std::fs::read(&path).into_diagnostic()?;
|
||||
|
||||
let mut working_set = StateWorkingSet::new(engine_state);
|
||||
|
10
src/repl.rs
10
src/repl.rs
@ -35,10 +35,6 @@ pub(crate) fn evaluate(
|
||||
// First, set up env vars as strings only
|
||||
gather_parent_env_vars(engine_state);
|
||||
|
||||
// Make a note of the exceptions we see for externals that look like math expressions
|
||||
let exceptions = crate::utils::external_exceptions();
|
||||
engine_state.external_exceptions = exceptions;
|
||||
|
||||
// Set up our initial config to start from
|
||||
stack.vars.insert(
|
||||
CONFIG_VARIABLE_ID,
|
||||
@ -86,6 +82,10 @@ pub(crate) fn evaluate(
|
||||
report_error(&working_set, &e);
|
||||
}
|
||||
|
||||
// Make a note of the exceptions we see for externals that look like math expressions
|
||||
let exceptions = crate::utils::external_exceptions(engine_state, &stack);
|
||||
engine_state.external_exceptions = exceptions;
|
||||
|
||||
// seed the cmd_duration_ms env var
|
||||
stack.add_env_var(
|
||||
"CMD_DURATION_MS".into(),
|
||||
@ -322,7 +322,7 @@ pub(crate) fn evaluate(
|
||||
}
|
||||
|
||||
// Make a note of the exceptions we see for externals that look like math expressions
|
||||
let exceptions = crate::utils::external_exceptions();
|
||||
let exceptions = crate::utils::external_exceptions(engine_state, &stack);
|
||||
engine_state.external_exceptions = exceptions;
|
||||
}
|
||||
Ok(Signal::CtrlC) => {
|
||||
|
@ -102,7 +102,7 @@ fn did_chop_arguments() -> bool {
|
||||
|
||||
for arg in arguments {
|
||||
let chopped = if arg.is_empty() {
|
||||
&arg
|
||||
arg
|
||||
} else {
|
||||
let to = arg.len() - 1;
|
||||
&arg[..to]
|
||||
|
49
src/utils.rs
49
src/utils.rs
@ -255,25 +255,50 @@ pub(crate) fn eval_source(
|
||||
}
|
||||
|
||||
/// Finds externals that have names that look like math expressions
|
||||
pub fn external_exceptions() -> Vec<Vec<u8>> {
|
||||
pub fn external_exceptions(engine_state: &EngineState, stack: &Stack) -> Vec<Vec<u8>> {
|
||||
let mut executables = vec![];
|
||||
|
||||
if let Ok(path) = std::env::var("PATH") {
|
||||
for path in std::env::split_paths(&path) {
|
||||
let path = path.to_string_lossy().to_string();
|
||||
if let Some(path) = stack.get_env_var(engine_state, "PATH") {
|
||||
match path {
|
||||
Value::List { vals, .. } => {
|
||||
for val in vals {
|
||||
let path = val.as_string();
|
||||
|
||||
if let Ok(mut contents) = std::fs::read_dir(path) {
|
||||
while let Some(Ok(item)) = contents.next() {
|
||||
if is_executable::is_executable(&item.path()) {
|
||||
if let Ok(name) = item.file_name().into_string() {
|
||||
let name = name.as_bytes().to_vec();
|
||||
if nu_parser::is_math_expression_like(&name) {
|
||||
executables.push(name);
|
||||
if let Ok(path) = path {
|
||||
if let Ok(mut contents) = std::fs::read_dir(path) {
|
||||
while let Some(Ok(item)) = contents.next() {
|
||||
if is_executable::is_executable(&item.path()) {
|
||||
if let Ok(name) = item.file_name().into_string() {
|
||||
let name = name.as_bytes().to_vec();
|
||||
if nu_parser::is_math_expression_like(&name) {
|
||||
executables.push(name);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
Value::String { val, .. } => {
|
||||
for path in std::env::split_paths(&val) {
|
||||
let path = path.to_string_lossy().to_string();
|
||||
|
||||
if let Ok(mut contents) = std::fs::read_dir(path) {
|
||||
while let Some(Ok(item)) = contents.next() {
|
||||
if is_executable::is_executable(&item.path()) {
|
||||
if let Ok(name) = item.file_name().into_string() {
|
||||
let name = name.as_bytes().to_vec();
|
||||
if nu_parser::is_math_expression_like(&name) {
|
||||
executables.push(name);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
_ => {}
|
||||
}
|
||||
}
|
||||
|
||||
@ -318,7 +343,7 @@ pub fn report_error(
|
||||
pub(crate) fn get_init_cwd() -> PathBuf {
|
||||
match std::env::current_dir() {
|
||||
Ok(cwd) => cwd,
|
||||
Err(_) => match std::env::var("PWD".to_string()) {
|
||||
Err(_) => match std::env::var("PWD") {
|
||||
Ok(cwd) => PathBuf::from(cwd),
|
||||
Err(_) => match nu_path::home_dir() {
|
||||
Some(cwd) => cwd,
|
||||
|
Reference in New Issue
Block a user