Skip to content

Commit

Permalink
Merge pull request #561 from mwallner/fix/psmodule-path-order
Browse files Browse the repository at this point in the history
Boxstarter doesn't override 'Write-Host' when in any non-Boxstarter shell/script
  • Loading branch information
flcdrg authored May 28, 2024
2 parents d9e2467 + 5651f41 commit 9266559
Showing 1 changed file with 10 additions and 4 deletions.
14 changes: 10 additions & 4 deletions BuildScripts/setup.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -216,6 +216,7 @@ function Create-Shortcut($location, $target, $targetArgs, $boxstarterPath) {

Move-Item -Path $tempFile $location -Force
}

function PersistBoxstarterPathToEnvironmentVariable($variableName, $boxstarterPath){
# Remove user scoped vars from previous releases
$userValue = [Environment]::GetEnvironmentVariable($variableName, 'User')
Expand All @@ -231,19 +232,24 @@ function PersistBoxstarterPathToEnvironmentVariable($variableName, $boxstarterPa
$value = [Environment]::GetEnvironmentVariable($variableName, 'Machine')
if($value){
$values=($value -split ';' | Where-Object { !($_.ToLower() -match "\\boxstarter$")}) -join ';'
$values="$boxstarterPath;$values"
}
elseif($variableName -eq "PSModulePath") {
$values = "$boxstarterPath;"
$values += [environment]::getfolderpath("ProgramFiles")
$values = [environment]::getfolderpath("ProgramFiles")
$values +="\WindowsPowerShell\Modules"
}
else {
$values ="$boxstarterPath"
}
# explicitly add boxstarterPath at the end of the env-var!
if (($values -split ';') -inotcontains $boxstarterPath) {
$values += ";$boxstarterPath"
}
$values = $values.Replace(';;',';')

[Environment]::SetEnvironmentVariable($variableName, $values, 'Machine')
$varValue = Get-Content env:\$variableName
$varValue = "$boxstarterPath;$varValue"
if (($varValue -split ';') -inotcontains $boxstarterPath) {
$varValue += ";$boxstarterPath"
}
Set-Content env:\$variableName -value $varValue
}

0 comments on commit 9266559

Please sign in to comment.