Repository navigation
Command not found should suggest how to install like in bash #1982
Copy link
Copy link
Closed
Labels
Issue-Enhancementthe issue is more of a feature request than a bugthe issue is more of a feature request than a bugUsability(LEGACY) Helps filter issues that might be higher priority because they directly affect usability(LEGACY) Helps filter issues that might be higher priority because they directly affect usabilityWG-Interactive-Consolethe console experiencethe console experience
Milestone
Description
Steps to reproduce
Run a command that's not installed on your Linux machine, e.g. dtrace.
Expected behavior
jasonsh@jasonsh-ubd02:~$ dtrace
The program 'dtrace' is currently not installed. You can install it by typing:
sudo apt-get install systemtap-sdt-dev
Actual behavior
PS> dtrace
dtrace : The term 'dtrace' is not recognized as the name of a cmdlet, function, script file, or operable program. Check
the spelling of the name, or if a path was included, verify that the path is correct and try again.
At line:1 char:1
+ dtrace
+ ~~~~~~
Environment data
PS /home/jasonsh> $PSVersionTable
Name Value
---- -----
PSVersion 6.0.0-alpha
PSEdition Core
PSCompatibleVersions {1.0, 2.0, 3.0, 4.0...}
BuildVersion 3.0.0.0
GitCommitId v6.0.0-alpha.9
CLRVersion
WSManStackVersion 3.0
PSRemotingProtocolVersion 2.3
SerializationVersion 1.1.0.1
PS /home/jasonsh> uname -v
#49~14.04.1-Ubuntu SMP Wed Jun 29 20:22:11 UTC 2016
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
Issue-Enhancementthe issue is more of a feature request than a bugthe issue is more of a feature request than a bugUsability(LEGACY) Helps filter issues that might be higher priority because they directly affect usability(LEGACY) Helps filter issues that might be higher priority because they directly affect usabilityWG-Interactive-Consolethe console experiencethe console experience
Activity
rkeithhill commentedon Aug 20, 2016
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)?
nerdshark commentedon Aug 21, 2016
This isn't built-in
bashfunctionality; it's normally defined as an error-handler callback (for error 127) in one of the system-wide shell profiles (probably in/etc/bashrc,/etc/profile, or/etc/profile.d/*).Keith Hill (@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.
SteveL-MSFT commentedon Jan 31, 2018
Need some api in PSGallery to enable this
BrucePay commentedon May 23, 2018
FYI: there's been a "command not found" action available in PowerShell since version 3.
BrucePay commentedon May 24, 2018
It turns out that the gallery does give you a way to look up modules containing a command
Find-Module -Command. So adding that to the hook code, you get something like this:The response from the gallery can be a bit slow, but you can always cancel the lookup with ctrl-C.
SteveL-MSFT commentedon May 25, 2018
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)
4 remaining items
Jawz84 commentedon Jul 12, 2018
What about changing the
CommandNotFoundExceptionto this: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
{0} -match "^\w+-\w+$"(this probably is not 100% correct regex to capture CmdLet verb-noun, but you get the idea).iricigor commentedon Nov 1, 2018
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
apt-get updatefrom Linux, and it follows what Ilya described above. More information is in the issue Steve opened.iSazonov commentedon Nov 2, 2018
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).
SteveL-MSFT commentedon Jun 10, 2020
Can also integrate with winget
ThomasNieto commentedon Aug 18, 2023
Steven Bucher (@StevenBucher98) can this issue be closed since its covered by feedback providers?
StevenBucher98 commentedon Aug 18, 2023
Fixed with Feedback Provider experimental feature