Skip to content

Possible issue with $HOME in windows #33

@JPHutchins

Description

@JPHutchins

Here's an example fix. The problem is that $HOME is defined but we sub it with $env:HOME

# Apply the additions to the system PATH
$global:_ENVR_PATH_ADDITIONS.GetEnumerator().ForEach({
    $key = $($_.Key)
    $val = $($_.Value)

    if ($null -eq $val) {
        continue
    }

    # expand the variables - Windows could have $env:<val> or $<val>
    $env_val = $ExecutionContext.InvokeCommand.ExpandString($val.Replace('$', '$env:'))
    $exp_val = $ExecutionContext.InvokeCommand.ExpandString($val)

    if ((Test-Path -Path "$env_val") -and (Test-Path -Path "$exp_val")) {
        Write-Host "ERROR - $key=$val is ambigious because both $env_val and $exp_val are valid paths" -ForegroundColor Red
        unsource
        exit 1
    }

    if (Test-Path -Path "$env_val") {
        $path_addition = $env_val
    } elseif (Test-Path -Path "$exp_val") {
        $path_addition = $exp_val
    } else {
        Write-Host "ERROR - $key=$val is not a directory." -ForegroundColor Red
        unsource
        exit 1
    }
    foreach ($folder in $(Get-Item env:path).value.split($([System.IO.Path]::PathSeparator))) {
        if ($folder -eq $path_addition) {
            $duplicate = 1
        }
    }
    if ($duplicate -eq 1) {
        continue
    }

    $Env:PATH = "$path_addition$([System.IO.Path]::PathSeparator)$Env:PATH"
})

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions