Last active
February 26, 2025 21:11
-
-
Save kizzx2/9282ea8b0e016960135d3c9ab88419e1 to your computer and use it in GitHub Desktop.
Revisions
-
kizzx2 revised this gist
Jan 23, 2018 . 1 changed file with 0 additions and 1 deletion.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -37,7 +37,6 @@ Try { Invoke-Expression ($args[$i..$args.length] -Join " ") } Finally { foreach($key in $ori.Keys) { New-Item -Name $key -Value $ori.Item($key) -ItemType Variable -Path Env: -Force > $null } } -
kizzx2 created this gist
Jan 23, 2018 .There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,43 @@ $ori = @{} Try { $i = 0 # Loading .env files if(Test-Path $args[0]) { foreach($line in (Get-Content $args[0])) { if($line -Match '^\s*$' -Or $line -Match '^#') { continue } $key, $val = $line.Split("=") $ori[$key] = if(Test-Path Env:\$key) { (Get-Item Env:\$key).Value } else { "" } New-Item -Name $key -Value $val -ItemType Variable -Path Env: -Force > $null } $i++ } while(1) { if($i -ge $args.length) { exit } if(!($args[$i] -Match '^[^ ]+=[^ ]+$')) { break } $key, $val = $args[$i].Split("=") $ori[$key] = if(Test-Path Env:\$key) { (Get-Item Env:\$key).Value } else { "" } New-Item -Name $key -Value $val -ItemType Variable -Path Env: -Force > $null $i++ } Invoke-Expression ($args[$i..$args.length] -Join " ") } Finally { foreach($key in $ori.Keys) { echo "Restoring $key to $($ori.Item($key))" New-Item -Name $key -Value $ori.Item($key) -ItemType Variable -Path Env: -Force > $null } }