Add support for math-like externals (#4606)

This commit is contained in:
JT
2022-02-22 10:55:28 -05:00
committed by GitHub
parent d054a724d1
commit 25712760ba
7 changed files with 63 additions and 4 deletions

View File

@ -57,6 +57,10 @@ fn main() -> Result<()> {
};
let _ = engine_state.merge_delta(delta, None, &init_cwd);
// 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;
// TODO: make this conditional in the future
// Ctrl-c protection section
let ctrlc = Arc::new(AtomicBool::new(false));

View File

@ -254,6 +254,32 @@ pub(crate) fn eval_source(
true
}
/// Finds externals that have names that look like math expressions
pub fn external_exceptions() -> 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 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);
}
}
}
}
}
}
}
executables
}
#[cfg(windows)]
pub fn enable_vt_processing() -> Result<(), ShellError> {
use crossterm_winapi::{ConsoleMode, Handle};