mirror of
https://github.com/ScoopInstaller/Scoop.git
synced 2026-09-29 16:57:06 +00:00
* Lint: PSPossibleIncorrectComparisonWithNull * Lint: PSUseLiteralInitializerForHashtable * Lint: PSUseBOMForUnicodeEncodedFile * Lint: PSUseApprovedVerbs * Lint: PSAvoidGlobalVars * Lint: PSAvoidUsingEmptyCatchBlock * Lint: PSUseShouldProcessForStateChangingFunctions * Lint helper: Add PSScriptAnalyzer integration for vscode * Fix lint: PSUseBOMForUnicodeEncodedFile * Tests: ignore previous TestResults.xml * Tests: add PowerShell script linting into tests! * Add PSScriptAnalyzer into appveyor ci * Update Scoop-Linting.Tests.ps1
44 lines
1.3 KiB
PowerShell
44 lines
1.3 KiB
PowerShell
# Usage: scoop which <command>
|
|
# Summary: Locate a shim/executable (similar to 'which' on Linux)
|
|
# Help: Locate the path to a shim/executable that was installed with Scoop (similar to 'which' on Linux)
|
|
param($command)
|
|
. "$psscriptroot\..\lib\core.ps1"
|
|
. "$psscriptroot\..\lib\help.ps1"
|
|
|
|
reset_aliases
|
|
|
|
if(!$command) { 'ERROR: <command> missing'; my_usage; exit 1 }
|
|
|
|
try {
|
|
$gcm = Get-Command "$command" -ea stop
|
|
} catch {
|
|
[console]::error.writeline("'$command' not found"); exit 3
|
|
}
|
|
|
|
$path = "$($gcm.path)"
|
|
$usershims = "$(resolve-path $(shimdir $false))"
|
|
$globalshims = fullpath (shimdir $true) # don't resolve: may not exist
|
|
|
|
if($path.endswith(".ps1") -and ($path -like "$usershims*" -or $path -like "$globalshims*")) {
|
|
$shimtext = Get-Content $path
|
|
|
|
$exepath = ($shimtext | Where-Object { $_.startswith('$path') }).split(' ') | Select-Object -Last 1 | Invoke-Expression
|
|
|
|
if(![system.io.path]::ispathrooted($exepath)) {
|
|
# Expand relative path
|
|
$exepath = resolve-path (join-path (split-path $path) $exepath)
|
|
}
|
|
|
|
friendly_path $exepath
|
|
} elseif($gcm.commandtype -eq 'Application') {
|
|
$gcm.Source
|
|
} elseif($gcm.commandtype -eq 'Alias') {
|
|
scoop which $gcm.resolvedcommandname
|
|
} else {
|
|
[console]::error.writeline("Not a scoop shim.")
|
|
$path
|
|
exit 2
|
|
}
|
|
|
|
exit 0
|