Skip to content

Instantly share code, notes, and snippets.

@Bak-Jin-Hyeong
Last active July 11, 2018 09:37
Show Gist options
  • Save Bak-Jin-Hyeong/8d217d30ec1dc75e7ff1397d42dbb125 to your computer and use it in GitHub Desktop.
Save Bak-Jin-Hyeong/8d217d30ec1dc75e7ff1397d42dbb125 to your computer and use it in GitHub Desktop.
$GOPATH = 'C:\BlahBlahBlah\Blah'
$GOPATH_BIN = "$GOPATH\bin"
$env:GOPATH = $GOPATH
if ($env:Path.IndexOf($GOPATH_BIN, [StringComparison]::OrdinalIgnoreCase) -lt 0)
{
if (($env:Path.Length -eq 0) -or ($env:Path[$env:Path.Length - 1] -eq ';'))
{
$env:Path += "$GOPATH_BIN"
}
else
{
$env:Path += ";$GOPATH_BIN"
}
}
if ($env:GOPATH.Length -le 0) {
return
}
$GOPATH_BIN = "$env:GOPATH\bin"
if ($GOPATH_BIN.Length -gt 0) {
$i = $env:Path.IndexOf($GOPATH_BIN)
if ($i -ge 0) {
$offset = $i
$len = $GOPATH_BIN.Length
if ($i -gt 0 -and $env:Path[$i - 1] -eq ';') {
$offset--
$len++
}
if (($offset -eq 0) -and ($len -lt $env:Path.Length) -and ($env:Path[$len] -eq ';')) {
$len++
}
$env:Path = $env:Path.Remove($offset, $len)
}
}
if ($GOBIN.Length -gt 0) {
$i = $env:Path.IndexOf($GOBIN)
if ($i -ge 0) {
$offset = $i
$len = $GOBIN.Length
if ($i -gt 0 -and $env:Path[$i - 1] -eq ';') {
$offset--
$len++
}
if (($offset -eq 0) -and ($len -lt $env:Path.Length) -and ($env:Path[$len] -eq ';')) {
$len++
}
$env:Path = $env:Path.Remove($offset, $len)
}
}
if (Test-Path Env:\GOPATH) {
Remove-Item Env:\GOPATH
}
if (Test-Path Env:\GOBIN) {
Remove-Item Env:\GOBIN
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment