-
Notifications
You must be signed in to change notification settings - Fork 80
Expand file tree
/
Copy pathload.ps1
More file actions
39 lines (32 loc) · 974 Bytes
/
Copy pathload.ps1
File metadata and controls
39 lines (32 loc) · 974 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
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
# Publish Markdown files to Confluence wiki.
#
# Copyright 2022-2026, Levente Hunyadi
# https://github.com/hunyadi/md2conf
# Sets environment variables defined in the file `.env` as KEY=VALUE pairs in the current environment context.
#
# Usage (a.k.a. dot-sourcing):
# ```
# . .\load.ps1
# ```
# path to the `.env` file
$envFile = ".env"
# check if the file exists
if (-Not (Test-Path $envFile)) {
Write-Error ".env file not found."
exit 1
}
# process file contents line by line
Get-Content $envFile | ForEach-Object {
$line = $_.Trim()
# skip empty lines and comments
if (-not $line -or $line.StartsWith("#")) {
return
}
# match lines in the format `KEY=VALUE`
if ($line -match '^\s*([^=]+?)\s*=\s*(.*)$') {
$key = $matches[1].Trim()
$value = $matches[2].Trim()
# set the environment variable in the current process
[System.Environment]::SetEnvironmentVariable($key, $value, "Process")
}
}