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
feat: Changed ENV variable name to allow for custom paths #5813
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -739,6 +739,14 @@ public static extern IntPtr SendMessageTimeout( | |
} | ||
|
||
function env($name, $global, $val = '__get') { | ||
if(-not $name) { | ||
$name = $scoop_path_env | ||
} | ||
|
||
if(-not $name) { | ||
throw "Unable to evaluate path environment variable. Please set or remove PATH_ENV in your config.json." | ||
} | ||
|
||
$RegisterKey = if ($global) { | ||
Get-Item -Path 'HKLM:\SYSTEM\CurrentControlSet\Control\Session Manager' | ||
} else { | ||
|
@@ -748,7 +756,7 @@ function env($name, $global, $val = '__get') { | |
|
||
if ($val -eq '__get') { | ||
$RegistryValueOption = [Microsoft.Win32.RegistryValueOptions]::DoNotExpandEnvironmentNames | ||
$EnvRegisterKey.GetValue($name, $null, $RegistryValueOption) | ||
$EnvRegisterKey.GetValue($name, $null, $RegistryValueOption) + "" | ||
} elseif ($val -eq $null) { | ||
try { $EnvRegisterKey.DeleteValue($name) } catch { } | ||
Publish-Env | ||
|
@@ -1010,7 +1018,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" | ||
|
@@ -1019,12 +1027,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 | ||
} | ||
} | ||
|
@@ -1113,8 +1121,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 | ||
|
@@ -1125,10 +1133,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 | ||
|
@@ -1415,6 +1423,8 @@ if ($pathExpected) { | |
} | ||
$scoopConfig = load_cfg $configFile | ||
|
||
$scoop_path_env = get_config PATH_ENV 'PATH' | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Recommend using a config option to check if use isolated path, and the PATH_ENV here could be There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I assumed we would want the default behavior to revert to the current behavior of just adding the paths to |
||
|
||
# Scoop root directory | ||
$scoopdir = $env:SCOOP, (get_config ROOT_PATH), (Resolve-Path "$PSScriptRoot\..\..\..\.."), "$([System.Environment]::GetFolderPath('UserProfile'))\scoop" | Where-Object { -not [String]::IsNullOrEmpty($_) } | Select-Object -First 1 | ||
|
||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What's this
""
for?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If the environment variable is empty we get a null exception later on. so we add the empty string to ensure it always returns a string even if the environment variable is empty.