-
Notifications
You must be signed in to change notification settings - Fork 7.6k
Command not found should suggest how to install like in bash #1982
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
Comments
That would be nice! Is there some repo/registry that maintains the mapping of "command to pkg name" for the various Linux distro's, as well as the pkg mgr to use (apt-get vs yum vs Install-Module)? |
This isn't built-in @rkeithhill It's not likely. Distros that support this kind of functionality generally do two or three things:
I don't think that using or maintaining an unofficial, centralized database of command-to-package mappings or package contents for multiple versions of multiple distros is the right approach. Instead, I think that Powershell should provide relevant error-handler hook points (or use existing ones) in the command loop and let Powershell packagers write callbacks tailored to their specific OS/package manager combination. This is in line with the existing practice above, and should require minimal effort to maintain. |
Need some api in PSGallery to enable this |
FYI: there's been a "command not found" action available in PowerShell since version 3. $executioncontext.InvokeCommand.CommandNotFoundAction = {
param ($e, $e2)
$e2.StopSearch = $true
$e2.CommandScriptblock = {
Write-Verbose -Verbose `
"Look for a module containing the command '$e somewhere"}.GetNewClosure()
}
} |
It turns out that the gallery does give you a way to look up modules containing a command $ExecutionContext.InvokeCommand.CommandNotFoundAction = {
param ($n, $e)
$e.StopSearch = $true
$e.CommandScriptBlock = {
Write-Host -ForegroundColor Yellow `
-Verbose "Command '$n' was not found; searching on-line for modules with this command"
$result = Find-Module -Command $n
if ($result)
{
$result | Out-String | Write-Host -ForegroundColor Yellow
}
else
{
Write-Host -ForegroundColor Yellow "No matching modules were found."
}
}.GetNewClosure()
} The response from the gallery can be a bit slow, but you can always cancel the lookup with ctrl-C. |
Opened https://github.com/PowerShell/PowerShellGet/issues/287, if they can get the perf down to 100ms or less, I think we can add this capability into PSCore6 (but probably need to have it timeout after 250ms to not impact the interactive experience) |
Web response time is not predictable. Can we use local cache like for help files? We could download a catalog and only check the catalog version and suggest users to update it. |
What about changing the
It's not as fancy as looking up an actual module automatically, but it does point users in the right direction, and it's super easy to implement. Maybe the extra line I propose here should only be displayed when |
I believe this functionality belongs to package management, but of course, it can/should be shipped together with PowerShell. I did proof-of-concept module which finds required information in about 20ms, so adding suggestions is not a problem. It is inspired with |
It will nice to have a public API (in PowerShellGet?) for fast search from the local cache - we could use the API in PowerShell engine for Help and IntelliSense subsystems. Perhaps PowerShell engine need generic API to search from some sources (preinstalled modules, custom modules, native commands and so on). |
Can also integrate with winget |
@StevenBucher98 can this issue be closed since its covered by feedback providers? |
Fixed with Feedback Provider experimental feature |
Steps to reproduce
Run a command that's not installed on your Linux machine, e.g.
dtrace
.Expected behavior
Actual behavior
Environment data
The text was updated successfully, but these errors were encountered: