From 8cf2f9b261e129926c8ea7f148fa7d6d1dd40128 Mon Sep 17 00:00:00 2001 From: Bahex Date: Sun, 10 Nov 2024 16:38:09 +0300 Subject: [PATCH] add const variable $current_file for script files script here refers to the entrypoint file when running scripts with nu like `nu script.nu` --- crates/nu-cli/src/eval_file.rs | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/crates/nu-cli/src/eval_file.rs b/crates/nu-cli/src/eval_file.rs index df75f7e4f8..58733e2a93 100644 --- a/crates/nu-cli/src/eval_file.rs +++ b/crates/nu-cli/src/eval_file.rs @@ -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);