Skip to content

Instantly share code, notes, and snippets.

@sevenc-nanashi
Created May 21, 2021 09:30
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save sevenc-nanashi/03a90c8dd4165e2244c24b227d923836 to your computer and use it in GitHub Desktop.
Save sevenc-nanashi/03a90c8dd4165e2244c24b227d923836 to your computer and use it in GitHub Desktop.
Source for windows powershell
Param($file = ".env")
$Datas = Get-Content $file
$EnvCount = 0
$CommentCount = 0
$CommandCount = 0
foreach ($Data in $Datas) {
If ($Data -match "^#") {
$CommentCount += 1
continue
}
Elseif ($Data -match "^.+=.+") {
$EnvCount += 1
Invoke-Expression ([regex]::Replace($Data, "^([^=]+)=""?([^=]+)""?$", { "`$env:" + $args.groups[1].value + "=""" + $args.groups[2].value + """" }, [System.Text.RegularExpressions.RegexOptions]::Multiline))
}
else {
$CommandCount+=1
Invoke-Expression $Data
}
}
write-host "Loaded " -NoNewline
write-host $EnvCount -NoNewline -ForegroundColor Cyan
write-host " Variable(s), " -NoNewline
write-host "Executed " -NoNewline
write-host $CommandCount -NoNewline -ForegroundColor Cyan
write-host " Command(s), " -NoNewline
write-host "Skipped " -NoNewline
write-host $CommentCount -NoNewline -ForegroundColor Cyan
write-host " Line(s)."
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment