From 45eb5eb7577444ff7b43648f699ef3fe5a3c1c85 Mon Sep 17 00:00:00 2001 From: abgox Date: Wed, 11 Mar 2026 14:46:36 +0800 Subject: [PATCH 1/5] feat(lib): allow env_add_path to use variables --- lib/install.ps1 | 18 ++++++++++++++++-- 1 file changed, 16 insertions(+), 2 deletions(-) diff --git a/lib/install.ps1 b/lib/install.ps1 index 78acdd252b..b9d2f96888 100644 --- a/lib/install.ps1 +++ b/lib/install.ps1 @@ -317,7 +317,14 @@ function env_add_path($manifest, $dir, $global, $arch) { if (get_config USE_ISOLATED_PATH) { Add-Path -Path ('%' + $scoopPathEnvVar + '%') -Global:$global } - $path = $env_add_path.Where({ $_ }).ForEach({ Join-Path $dir $_ | Get-AbsolutePath }).Where({ is_in_dir $dir $_ }) + $path = $env_add_path.Where({ $_ }) | ForEach-Object { + $path_expand = $ExecutionContext.InvokeCommand.ExpandString($_) + if($path_expand -eq $_){ + Join-Path $dir $_ | Get-AbsolutePath | Where-Object { is_in_dir $dir $_ } + }else{ + $path_expand + } + } Add-Path -Path $path -TargetEnvVar $scoopPathEnvVar -Global:$global -Force } } @@ -326,7 +333,14 @@ function env_rm_path($manifest, $dir, $global, $arch) { $env_add_path = arch_specific 'env_add_path' $manifest $arch $dir = $dir.TrimEnd('\') if ($env_add_path) { - $path = $env_add_path.Where({ $_ }).ForEach({ Join-Path $dir $_ | Get-AbsolutePath }).Where({ is_in_dir $dir $_ }) + $path = $env_add_path.Where({ $_ }) | ForEach-Object { + $path_expand = $ExecutionContext.InvokeCommand.ExpandString($_) + if($path_expand -eq $_){ + Join-Path $dir $_ | Get-AbsolutePath | Where-Object { is_in_dir $dir $_ } + }else{ + $path_expand + } + } Remove-Path -Path $path -Global:$global # TODO: Remove after forced isolating Scoop path Remove-Path -Path $path -TargetEnvVar $scoopPathEnvVar -Global:$global } From 7991f7a903d60a0b9b2ea07a481b474c8dd32e79 Mon Sep 17 00:00:00 2001 From: abgox Date: Wed, 11 Mar 2026 14:46:37 +0800 Subject: [PATCH 2/5] feat(lib): allow shortcuts to use variables --- lib/shortcuts.ps1 | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/lib/shortcuts.ps1 b/lib/shortcuts.ps1 index edb6357480..ba8ce1d533 100644 --- a/lib/shortcuts.ps1 +++ b/lib/shortcuts.ps1 @@ -2,7 +2,10 @@ function create_startmenu_shortcuts($manifest, $dir, $global, $arch) { $shortcuts = @(arch_specific 'shortcuts' $manifest $arch) $shortcuts | Where-Object { $_ -ne $null } | ForEach-Object { - $target = [System.IO.Path]::Combine($dir, $_.item(0)) + $target = $ExecutionContext.InvokeCommand.ExpandString($_.item(0)) + if($target -eq $_.item(0)){ + $target = [System.IO.Path]::Combine($dir, $_.item(0)) + } $target = New-Object System.IO.FileInfo($target) $name = $_.item(1) $arguments = '' @@ -11,7 +14,10 @@ function create_startmenu_shortcuts($manifest, $dir, $global, $arch) { $arguments = $_.item(2) } if ($_.length -ge 4) { - $icon = [System.IO.Path]::Combine($dir, $_.item(3)) + $icon = $ExecutionContext.InvokeCommand.ExpandString($_.item(3)) + if($icon -eq $_.item(3)){ + $icon = [System.IO.Path]::Combine($dir, $_.item(3)) + } $icon = New-Object System.IO.FileInfo($icon) } $arguments = (substitute $arguments @{ '$dir' = $dir; '$original_dir' = $original_dir; '$persist_dir' = $persist_dir }) From 3c055710f53a2aa28dd2a23f2ba18bf84a7cd7a4 Mon Sep 17 00:00:00 2001 From: abgox Date: Wed, 11 Mar 2026 14:52:51 +0800 Subject: [PATCH 3/5] docs(changelog): update CHANGLOG --- CHANGELOG.md | 1 + 1 file changed, 1 insertion(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 1b5933ca2a..144ff603c0 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -7,6 +7,7 @@ - **install:** Add separator at the end of notes, highlight suggestions ([#6418](https://github.com/ScoopInstaller/Scoop/issues/6418)) - **download|scoop-download:** Add GitHub issue prompt when the default downloader fails ([#6539](https://github.com/ScoopInstaller/Scoop/issues/6539)) - **download|scoop-config:** Allow disabling automatic fallback to the default downloader when Aria2c download fails ([#6538](https://github.com/ScoopInstaller/Scoop/issues/6538)) +- **lib** Allow `env_add_path` and `shortcuts` field to use variables ([#6616](https://github.com/ScoopInstaller/Scoop/issues/6616)) ### Bug Fixes From 761122247a3e5e5688c45693e6e5782c9667db45 Mon Sep 17 00:00:00 2001 From: abgox Date: Wed, 11 Mar 2026 17:52:07 +0800 Subject: [PATCH 4/5] feat: allow env_add_path to include variables defined in env_set --- lib/install.ps1 | 2 +- libexec/scoop-reset.ps1 | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/install.ps1 b/lib/install.ps1 index b9d2f96888..a33c89b0d1 100644 --- a/lib/install.ps1 +++ b/lib/install.ps1 @@ -59,8 +59,8 @@ function install_app($app, $architecture, $global, $suggested, $use_cache = $tru create_shims $manifest $dir $global $architecture create_startmenu_shortcuts $manifest $dir $global $architecture install_psmodule $manifest $dir $global - env_add_path $manifest $dir $global $architecture env_set $manifest $global $architecture + env_add_path $manifest $dir $global $architecture # persist data persist_data $manifest $original_dir $persist_dir diff --git a/libexec/scoop-reset.ps1 b/libexec/scoop-reset.ps1 index 1dd000a373..72fb011c7e 100644 --- a/libexec/scoop-reset.ps1 +++ b/libexec/scoop-reset.ps1 @@ -83,8 +83,8 @@ $apps | ForEach-Object { # unset all potential old env before re-adding env_rm_path $manifest $dir $global $architecture env_rm $manifest $global $architecture - env_add_path $manifest $dir $global $architecture env_set $manifest $global $architecture + env_add_path $manifest $dir $global $architecture # unlink all potential old link before re-persisting unlink_persist_data $manifest $original_dir persist_data $manifest $original_dir $persist_dir From 0c22b2374e26231a149878e48a0abaae18fd9817 Mon Sep 17 00:00:00 2001 From: abgox Date: Wed, 11 Mar 2026 18:20:16 +0800 Subject: [PATCH 5/5] refactor: use -like to check variables --- lib/install.ps1 | 14 ++++++-------- lib/shortcuts.ps1 | 16 ++++++++++------ 2 files changed, 16 insertions(+), 14 deletions(-) diff --git a/lib/install.ps1 b/lib/install.ps1 index a33c89b0d1..1d78415be2 100644 --- a/lib/install.ps1 +++ b/lib/install.ps1 @@ -318,11 +318,10 @@ function env_add_path($manifest, $dir, $global, $arch) { Add-Path -Path ('%' + $scoopPathEnvVar + '%') -Global:$global } $path = $env_add_path.Where({ $_ }) | ForEach-Object { - $path_expand = $ExecutionContext.InvokeCommand.ExpandString($_) - if($path_expand -eq $_){ - Join-Path $dir $_ | Get-AbsolutePath | Where-Object { is_in_dir $dir $_ } + if ($_ -like '$*'){ + $ExecutionContext.InvokeCommand.ExpandString($_) }else{ - $path_expand + Join-Path $dir $_ | Get-AbsolutePath | Where-Object { is_in_dir $dir $_ } } } Add-Path -Path $path -TargetEnvVar $scoopPathEnvVar -Global:$global -Force @@ -334,11 +333,10 @@ function env_rm_path($manifest, $dir, $global, $arch) { $dir = $dir.TrimEnd('\') if ($env_add_path) { $path = $env_add_path.Where({ $_ }) | ForEach-Object { - $path_expand = $ExecutionContext.InvokeCommand.ExpandString($_) - if($path_expand -eq $_){ - Join-Path $dir $_ | Get-AbsolutePath | Where-Object { is_in_dir $dir $_ } + if ($_ -like '$*'){ + $ExecutionContext.InvokeCommand.ExpandString($_) }else{ - $path_expand + Join-Path $dir $_ | Get-AbsolutePath | Where-Object { is_in_dir $dir $_ } } } Remove-Path -Path $path -Global:$global # TODO: Remove after forced isolating Scoop path diff --git a/lib/shortcuts.ps1 b/lib/shortcuts.ps1 index ba8ce1d533..f730aa97f5 100644 --- a/lib/shortcuts.ps1 +++ b/lib/shortcuts.ps1 @@ -2,9 +2,11 @@ function create_startmenu_shortcuts($manifest, $dir, $global, $arch) { $shortcuts = @(arch_specific 'shortcuts' $manifest $arch) $shortcuts | Where-Object { $_ -ne $null } | ForEach-Object { - $target = $ExecutionContext.InvokeCommand.ExpandString($_.item(0)) - if($target -eq $_.item(0)){ - $target = [System.IO.Path]::Combine($dir, $_.item(0)) + $target = $_.item(0) + if($target -like '$*'){ + $target = $ExecutionContext.InvokeCommand.ExpandString($target) + }else{ + $target = [System.IO.Path]::Combine($dir, $target) } $target = New-Object System.IO.FileInfo($target) $name = $_.item(1) @@ -14,9 +16,11 @@ function create_startmenu_shortcuts($manifest, $dir, $global, $arch) { $arguments = $_.item(2) } if ($_.length -ge 4) { - $icon = $ExecutionContext.InvokeCommand.ExpandString($_.item(3)) - if($icon -eq $_.item(3)){ - $icon = [System.IO.Path]::Combine($dir, $_.item(3)) + $icon = $_.item(3) + if($icon -like '$*'){ + $icon = $ExecutionContext.InvokeCommand.ExpandString($icon) + }else{ + $icon = [System.IO.Path]::Combine($dir, $icon) } $icon = New-Object System.IO.FileInfo($icon) }