Skip to content

Commit fe1532c

Browse files
committed
⚗ Investigate making Use-Command.ps1 more cross-platform
- resolves brianary#40
1 parent bb021aa commit fe1532c

File tree

1 file changed

+7
-0
lines changed

1 file changed

+7
-0
lines changed

Use-Command.ps1

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -123,13 +123,20 @@ Default is 32767
123123
[Parameter(ParameterSetName='Fail')]
124124
[switch] $Fail
125125
)
126+
126127
function Set-ResolvedAlias([Parameter(Position=0)][string]$Name,[Parameter(Position=1)][string]$Path)
127128
{
128129
Set-Alias $Name (Resolve-Path $Path -EA SilentlyContinue |Select-Object -ExpandProperty Path |Find-NewestFile.ps1 |
129130
Select-Object -ExpandProperty FullName) -Scope Global
130131
}
131132
if((Get-Command $Name -ErrorAction Ignore)) { Write-Verbose "$Name command found." ; return }
132133
if($Path -and (Test-Path $Path)) { Set-ResolvedAlias $Name $Path ; return }
134+
if((!$IsWindows) -and $IsLinux)
135+
{
136+
if (Get-Command /usr/lib/command-not-found -Type Application) { /usr/lib/command-not-found $Name }
137+
elseif (Get-Command apropos -Type Application) { apropos $Name }
138+
Stop-ThrowError.ps1 "Command '$Name' not available!" -SearchContext $Name
139+
}
133140

134141
switch($PSCmdlet.ParameterSetName)
135142
{

0 commit comments

Comments
 (0)