Skip to content

Commit

Permalink
fix(core): Handle scoop aliases and broken (edited,copied) shim (#5551)
Browse files Browse the repository at this point in the history
* fix(core): Avoid error messages when shim broked, Allow get path for scoop aliases

* update `scoop-which`

* Add CHANGELOG entry

* Update CHANGELOG.md

Co-authored-by: Rashil Gandhi <46838874+rashil2000@users.noreply.github.com>

---------

Co-authored-by: Rashil Gandhi <46838874+rashil2000@users.noreply.github.com>
  • Loading branch information
HUMORCE and rashil2000 authored Oct 3, 2023
1 parent 00c92b0 commit 6d79d62
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 4 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
- **core:** Fix `is_in_dir` under Unix ([#5391](https://github.com/ScoopInstaller/Scoop/issues/5391))
- **core:** Rewrite config file when needed ([#5439](https://github.com/ScoopInstaller/Scoop/issues/5439))
- **core:** Prevents leaking HTTP(S)_PROXY env vars to current sessions after Invoke-Git in parallel execution ([#5436](https://github.com/ScoopInstaller/Scoop/pull/5436))
- **core:** Handle scoop aliases and broken(edited,copied) shim ([#5551](https://github.com/ScoopInstaller/Scoop/issues/5551))
- **env:** Avoid automatic expansion of `%%` in env ([#5395](https://github.com/ScoopInstaller/Scoop/issues/5395), [#5452](https://github.com/ScoopInstaller/Scoop/pull/5452), [#5631](https://github.com/ScoopInstaller/Scoop/pull/5631))
- **install:** Fix download from private GitHub repositories ([#5361](https://github.com/ScoopInstaller/Scoop/issues/5361))
- **install:** Avoid error when unlinking non-existent junction/hardlink ([#5552](https://github.com/ScoopInstaller/Scoop/issues/5552))
Expand Down
7 changes: 5 additions & 2 deletions lib/core.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -469,7 +469,10 @@ function Get-CommandPath {
} catch {
return $null
}
$commandPath = if ($comm.Path -like "$userShims*" -or $comm.Path -like "$globalShims*") {
$commandPath = if ($comm.Path -like "$userShims\scoop-*.ps1") {
# Scoop aliases
$comm.Source
} elseif ($comm.Path -like "$userShims*" -or $comm.Path -like "$globalShims*") {
Get-ShimTarget ($comm.Path -replace '\.exe$', '.shim')
} elseif ($comm.CommandType -eq 'Application') {
$comm.Source
Expand Down Expand Up @@ -847,7 +850,7 @@ function Get-ShimTarget($ShimPath) {
if (!$shimTarget) {
$shimTarget = ((Select-String -Path $ShimPath -Pattern '[''"]([^@&]*?)[''"]' -AllMatches).Matches.Groups | Select-Object -Last 1).Value
}
$shimTarget | Convert-Path
$shimTarget | Convert-Path -ErrorAction SilentlyContinue
}
}

Expand Down
4 changes: 2 additions & 2 deletions libexec/scoop-which.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,15 @@
param($command)

if (!$command) {
'ERROR: <command> missing'
error '<command> missing'
my_usage
exit 1
}

$path = Get-CommandPath $command

if ($null -eq $path) {
Write-Host "'$command' not found / not a scoop shim."
warn "'$command' not found, not a scoop shim, or a broken shim."
exit 2
} else {
friendly_path $path
Expand Down

0 comments on commit 6d79d62

Please sign in to comment.