From df78a51e8d86d5c58f323633cd63a0929853e354 Mon Sep 17 00:00:00 2001 From: CEbbinghaus Date: Tue, 27 Feb 2024 18:24:51 +1100 Subject: [PATCH] Changed ENV variable name to allow for custom paths --- lib/core.ps1 | 23 +++++++++++++++-------- lib/install.ps1 | 6 +++--- 2 files changed, 18 insertions(+), 11 deletions(-) diff --git a/lib/core.ps1 b/lib/core.ps1 index bc0365eb03..01c8d37779 100644 --- a/lib/core.ps1 +++ b/lib/core.ps1 @@ -589,8 +589,15 @@ function Invoke-ExternalCommand { } function env($name,$global,$val='__get') { + if(-not $name) { + $name = [environment]::getEnvironmentVariable("SCOOP_ENV", "User") + if(-not $name) { + $name = 'PATH' + } + } + $target = 'User'; if($global) {$target = 'Machine'} - if($val -eq '__get') { [environment]::getEnvironmentVariable($name,$target) } + if($val -eq '__get') { [environment]::getEnvironmentVariable($name,$target) + "" } else { [environment]::setEnvironmentVariable($name,$val,$target) } } @@ -843,7 +850,7 @@ function get_shim_path() { } function search_in_path($target) { - $path = (env 'PATH' $false) + ";" + (env 'PATH' $true) + $path = (env $Null $false) + ";" + (env $Null $true) foreach($dir in $path.split(';')) { if(test-path "$dir\$target" -pathType leaf) { return "$dir\$target" @@ -852,12 +859,12 @@ function search_in_path($target) { } function ensure_in_path($dir, $global) { - $path = env 'PATH' $global + $path = env $Null $global $dir = fullpath $dir if($path -notmatch [regex]::escape($dir)) { write-output "Adding $(friendly_path $dir) to $(if($global){'global'}else{'your'}) path." - env 'PATH' $global "$dir;$path" # for future sessions... + env $Null $global "$dir;$path" # for future sessions... $env:PATH = "$dir;$env:PATH" # for this session } } @@ -946,8 +953,8 @@ function add_first_in_path($dir, $global) { $dir = fullpath $dir # future sessions - $null, $currpath = strip_path (env 'path' $global) $dir - env 'path' $global "$dir;$currpath" + $null, $currpath = strip_path (env $Null $global) $dir + env $Null $global "$dir;$currpath" # this session $null, $env:PATH = strip_path $env:PATH $dir @@ -958,10 +965,10 @@ function remove_from_path($dir, $global) { $dir = fullpath $dir # future sessions - $was_in_path, $newpath = strip_path (env 'path' $global) $dir + $was_in_path, $newpath = strip_path (env $Null $global) $dir if($was_in_path) { Write-Output "Removing $(friendly_path $dir) from your path." - env 'path' $global $newpath + env $Null $global $newpath } # current session diff --git a/lib/install.ps1 b/lib/install.ps1 index cdbfdf1a79..ee64af6729 100644 --- a/lib/install.ps1 +++ b/lib/install.ps1 @@ -935,16 +935,16 @@ function unlink_current($versiondir) { # to undo after installers add to path so that scoop manifest can keep track of this instead function ensure_install_dir_not_in_path($dir, $global) { - $path = (env 'path' $global) + $path = (env $Null $global) $fixed, $removed = find_dir_or_subdir $path "$dir" if($removed) { $removed | ForEach-Object { "Installer added '$(friendly_path $_)' to path. Removing."} - env 'path' $global $fixed + env $Null $global $fixed } if(!$global) { - $fixed, $removed = find_dir_or_subdir (env 'path' $true) "$dir" + $fixed, $removed = find_dir_or_subdir (env $Null $true) "$dir" if($removed) { $removed | ForEach-Object { warn "Installer added '$_' to system path. You might want to remove this manually (requires admin permission)."} }