forked from wyeeeee/hajimi
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathenv.ps1
More file actions
24 lines (22 loc) · 698 Bytes
/
env.ps1
File metadata and controls
24 lines (22 loc) · 698 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
function Load-EnvVariables {
param (
[string]$EnvFilePath = ".\.env"
)
if (Test-Path -Path $EnvFilePath) {
$envContent = Get-Content -Path $EnvFilePath
foreach ($line in $envContent) {
if ($line -notmatch '^\s*(#|$)') {
$keyValue = $line -split '=', 2
if ($keyValue.Length -eq 2) {
$key = $keyValue[0].Trim()
$value = $keyValue[1].Trim()
Set-Item -Path "env:$key" -Value $value
}
}
}
} else {
Write-Warning "未找到.env文件: $EnvFilePath"
}
}
# 调用函数来加载环境变量
Load-EnvVariables