-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcmd-posh-bridge.psm1
31 lines (28 loc) · 934 Bytes
/
cmd-posh-bridge.psm1
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
$uuid = "59985486-5787-4770-9b23-da9182e660b7"
# UUID should be unique, consider to generate a new uuid if you folk this repo
function Import-CmdEnv() {
[CmdletBinding()]
Param(
[string]$CmdPath
)
$c = get_cmd_set($CmdPath)
import_env($c) | Out-Null
}
function get_cmd_set($CmdPath) {
$file = Get-Item $CmdPath -ErrorAction Stop
$output = cmd /Q /C "`"$($file.FullName)`" & echo. & echo $uuid & set"
Write-Verbose (Join-String -InputObject $output -Separator "`n")
$output = $output[([Array]::LastIndexOf($output, $uuid) + 1)..$output.Length]
return $output
}
function import_env($env_str) {
Push-Location Env:
foreach ($line in $env_str) {
if ($line -Match '^(.*?)=(.*)$') {} else { continue }
$name = $Matches[1]
$value = $Matches[2]
Set-Content -Path $name -Value $value
}
Pop-Location
}
Export-ModuleMember -Function Import-CmdEnv