@@ -12,6 +12,7 @@ use libpkgx::{
1212 config:: Config , env, hydrate:: hydrate, install_multi, pantry_db, resolve:: resolve, sync,
1313 types:: PackageReq , utils,
1414} ;
15+ use regex:: Regex ;
1516use rusqlite:: Connection ;
1617use serde_json:: json;
1718
@@ -207,6 +208,21 @@ async fn main() -> Result<(), Box<dyn Error>> {
207208 let env = env:: mix ( env) ;
208209 let mut env = env:: mix_runtime ( & env, & installations, & conn) ?;
209210
211+ let re = Regex :: new ( r"^\$\{\w+:-([^}]+)\}$" ) . unwrap ( ) ;
212+
213+ for ( key, value) in env. clone ( ) {
214+ if let Some ( caps) = re. captures ( & value) {
215+ env. insert ( key, caps. get ( 1 ) . unwrap ( ) . as_str ( ) . to_string ( ) ) ;
216+ } else {
217+ let cleaned_value = value
218+ . replace ( & format ! ( ":${}" , key) , "" )
219+ . replace ( & format ! ( "${}:" , key) , "" )
220+ . replace ( & format ! ( "; ${}" , key) , "" ) // one pantry instance of this
221+ . replace ( & format ! ( "${}" , key) , "" ) ;
222+ env. insert ( key, cleaned_value) ;
223+ }
224+ }
225+
210226 // fork bomb protection
211227 env. insert ( "PKGX_LVL" . to_string ( ) , pkgx_lvl. to_string ( ) ) ;
212228
@@ -220,7 +236,11 @@ async fn main() -> Result<(), Box<dyn Error>> {
220236 let env = env. iter ( ) . map ( |( k, v) | ( k. clone ( ) , v. join ( ":" ) ) ) . collect ( ) ;
221237 let env = env:: mix_runtime ( & env, & installations, & conn) ?;
222238 for ( key, value) in env {
223- println ! ( "{}=\" {}${{{}:+:${}}}\" " , key, value, key, key) ;
239+ println ! (
240+ "{}=\" {}\" " ,
241+ key,
242+ value. replace( & format!( ":${}" , key) , & format!( "${{{}:+:${}}}" , key, key) )
243+ ) ;
224244 }
225245 } else {
226246 let mut runtime_env = HashMap :: new ( ) ;
0 commit comments