15 lines
610 B
PowerShell
15 lines
610 B
PowerShell
function Import-DeployDotEnv {
|
|
param([string]$Path)
|
|
if (-not (Test-Path $Path)) { return }
|
|
Get-Content $Path | ForEach-Object {
|
|
if ($_ -match '^\s*#' -or $_ -match '^\s*$') { return }
|
|
if ($_ -match '^([A-Za-z_][A-Za-z0-9_]*)=(.*)$') {
|
|
$name = $Matches[1]; $raw = $Matches[2].Trim()
|
|
$v = $raw
|
|
if ($raw.StartsWith("'") -and $raw.EndsWith("'")) { $v = $raw.Trim("'") }
|
|
elseif ($raw.StartsWith('"') -and $raw.EndsWith('"')) { $v = $raw.Trim('"') }
|
|
[Environment]::SetEnvironmentVariable($name, $v, "Process")
|
|
}
|
|
}
|
|
}
|