Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Possible issue with $HOME in windows #33

Open
JPHutchins opened this issue Jul 25, 2024 · 0 comments
Open

Possible issue with $HOME in windows #33

JPHutchins opened this issue Jul 25, 2024 · 0 comments

Comments

@JPHutchins
Copy link
Owner

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"
})
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant