add const variable $current_file for script files

script here refers to the entrypoint file when running scripts with nu
like `nu script.nu`
This commit is contained in:
Bahex 2024-11-10 16:38:09 +03:00
parent 7901f29445
commit 8cf2f9b261

View File

@ -74,6 +74,18 @@ pub fn evaluate_file(
.expect("internal error: missing filename");
let mut working_set = StateWorkingSet::new(engine_state);
let current_file = working_set.add_variable(
b"$current_file".into(),
Span::unknown(),
nu_protocol::Type::String,
false,
);
working_set.set_variable_const_val(
current_file,
Value::string(file_path.to_string_lossy(), Span::unknown()),
);
trace!("parsing file: {}", file_path_str);
let block = parse(&mut working_set, Some(file_path_str), &file, false);