@@ -47,7 +47,7 @@ impl Command for SourceEnv {
4747 let block_id: i64 = call. req_parser_info ( engine_state, caller_stack, "block_id" ) ?;
4848
4949 // Set the currently evaluated directory (file-relative PWD)
50- let mut parent = if let Some ( path) = find_in_dirs_env (
50+ let file_path = if let Some ( path) = find_in_dirs_env (
5151 & source_filename. item ,
5252 engine_state,
5353 caller_stack,
@@ -57,11 +57,17 @@ impl Command for SourceEnv {
5757 } else {
5858 return Err ( ShellError :: FileNotFound ( source_filename. span ) ) ;
5959 } ;
60- parent. pop ( ) ;
6160
62- let file_pwd = Value :: string ( parent. to_string_lossy ( ) , call. head ) ;
61+ if let Some ( parent) = file_path. parent ( ) {
62+ let file_pwd = Value :: string ( parent. to_string_lossy ( ) , call. head ) ;
6363
64- caller_stack. add_env_var ( "FILE_PWD" . to_string ( ) , file_pwd) ;
64+ caller_stack. add_env_var ( "FILE_PWD" . to_string ( ) , file_pwd) ;
65+ }
66+
67+ caller_stack. add_env_var (
68+ "CURRENT_FILE" . to_string ( ) ,
69+ Value :: string ( file_path. to_string_lossy ( ) , call. head ) ,
70+ ) ;
6571
6672 // Evaluate the block
6773 let block = engine_state. get_block ( block_id as usize ) . clone ( ) ;
@@ -81,6 +87,7 @@ impl Command for SourceEnv {
8187
8288 // Remove the file-relative PWD
8389 caller_stack. remove_env_var ( engine_state, "FILE_PWD" ) ;
90+ caller_stack. remove_env_var ( engine_state, "CURRENT_FILE" ) ;
8491
8592 result
8693 }
0 commit comments