Created
May 21, 2021 09:30
-
-
Save sevenc-nanashi/03a90c8dd4165e2244c24b227d923836 to your computer and use it in GitHub Desktop.
Source for windows powershell
This file contains 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 characters
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