“Command Not Found” Plasma Runner

As promised, an explanation.

This is the “Command Not Found” runner. For those of you who may not be familiar, command-not-found is a magical little command line tool that gets activated when the shell cannot find the binary you wish to launch. It has a database of binaries and package names, and can check to see which package contains the binary you tried to type. If it finds one, it tells you which package to install to get this binary.

But I find that I use KRunner for launching my stuff more often these days. On new installs, I instinctually go to KRunner and try to type in the name of my favorite app.  But then I get nothing; realizing that this is a new install and I have yet to install this piece of software. I mumble, backspace, and type in the name of my favorite package manager. I then type in the name of the application I wanted (again) and mark it for installation.

…but wouldn’t it be nice if I didn’t have to? I don’t anymore, thanks to the Command Not Found runner. I was browsing the KDE brainstorm section of the KDE forums and saw this idea. I thought it was neat and actually feasible, so yesterday I sat down and hacked. By the end of the day, the installer/command not found runner was born!

Here’s how it works: Whenever KRunner cannot find an application via KService, the Command Not Found runner takes what you typed and tells the command-not-found utility to find which package has that program. If command-not-found finds anything, the runner returns a result. Click that result, and it starts qapt-batch, telling it to install that package. You just have to enter your password, and qapt-batch will do all the rest. Neat!

As an added bonus, if the runner detects that the program you are trying to run has a different name than the package it is in, it gives a nice, helpful little subtext that explains that the amarok package contains “amarokpkg”, even though the package isn’t named “amarokpkg”.

A few notes based on the comments my mysterious post last night introduced:

  • This is not meant to replace traditional package management. It is just a little convenience feature that can only ever install things that aren’t installed. It will never do anything more than that package management-wise.
  • Going back to the first point, it is (in general) a good thing that you have to know the exact name of the program to get this to show up. It limits the usecase of this service to those who forgot that they hadn’t installed $app yet, and will have a very small likelihood of showing up for somebody who is not trying to run $app. There would really be no reason to not enable this by default, especially since KRunner is somewhat of a hidden feature in the first place…
  • The KRunner plugin can be turned off.
  • It does not do any package management itself. It leaves the installation to a real batch installer program.
  • If the user does not have the privileges to install packages, it will not show up.

At the moment, it only works on Debian-based systems, since it requires the Debian command-not-found program. Sorry ’bout that. 😦 I just don’t see a way that this could be done in a cross-distro manner right now… It was simple to code, however, so it shouldn’t be too much trouble to make one for another distro, if you know how their command-not-found works (if they have one, of course)

Going back to the KDE Brainstorm post, it is definitely feasible to add this to Kickoff. It does require a one-line patch, however, so that pretty much limits it to people who want to patch kickoff themselves to get the runner to show results there… It would be neat if we could make certain “categories” of runners, and then have kickoff configured to only show the results of certain categories. At the moment there’s a whitelist that you have to add to before they’ll show.

I’ll try to get packages up in the next few days, but due to my impending vacation I don’t know how successful I’ll be in actually getting around to it. You can grab the source here if you want to. It should just need kdelibs5-dev to build.


21 Responses to “Command Not Found” Plasma Runner

  1. Sławek says:

    Ubuntu Add/Remove program(maybe software center too) offers buttons to run application after installation.

    Of course, I don’t know it is connected to PackageKit, but probably Ubuntu don’t support PackageKit.

    There should exists option to ask run this program/command after installation.

  2. flows says:

    Best plugin ever 😀 😉 Thanks!

  3. Christian says:

    “I just don’t see a way that this could be done in a cross-distro manner right now…”

    What about PackageKit? In Fedora, there is PackageKit-command-not-found, described as “a simple helper that offers to install new packages on the command line using PackageKit”.

  4. TheBlackCat says:

    openSUSE has a version of command-not-found as well.

    • The output is likely to differ from the Debian version. It would be possible to support it, too, if I could get some samples of its output.

      • Diederik van der Boor says:

        The command-not-found (or `cnf` app) on openSUSE 11.3 is actually a python script. – which also has a backend module.

        Perhaps it’s better if you check this out (instead of output parsing) or have someone from openSUSE look at it 😉

      • Actually, if it outputs that I believe it would work. It currently takes a look at the last line outputted by command-not-found, checks to see if it starts with “sudo”, and then takes the last word of that line and assumes it is the package. SuSE users would just have to patch the c-n-f binary location as well as replace qapt-batch with whatever batch installer you use.

      • peter says:


        If ‘kbreakout’ is not a typo you can use command-not-found to lookup the package that contains it, like this:
        cnf kbreakout

        $cnf kbreakout

        Das Programm ‘kbreakout’ kann in den folgenden Paketen gefunden werden:
        * kbreakout [ Pfad: /usr/bin/bovo, Repository: zypp (openSUSE-11.3_) ]
        * kbreakout [ Pfad: /usr/bin/bovo, Repository: zypp (KDE_Factory) ]

        Try installing with:
        sudo zypper install kbreakout

  5. ivar says:

    Package kit is distro agnostic and *should* work in most distros in the near future. (Maybe not the Debian based distros as they like to be different than the rest).

  6. pvandewyngaerde says:

    maybe this is related:
    RFC: On-demand package installation API in kdelibs on mailinglist kde-core-devel

  7. kurtisharms says:

    Definitely one of the best KDE plugins that I’ve seen! 😉 Could you please submit this for inclusion in Kubuntu?

  8. Albert says:

    For the packagekit agnostic I do think that it’s fundamuntaly flowed for the simple reason that PK is trying to have the “least common denominator” of all apckage management. I will give you a simple example how PK is stupid: install kubuntu, yes you do have PK, and try to replace network-manager-kde with plasma-widget-networkmanagement with PK, it’s not working but with synaptic or apt-get there are no problem at all. Another point the GUI to use PK is just stupid and very very difficult to use.

  9. Zygmunt Krynicki says:

    W00t 🙂

    This is indeed very cool. I wrote the Ubuntu command-not-found program and I never imagined people would take it to that level.

    Is there any way for you to use D-Bus services instead? Current c-n-f development tree has migrated into a d-bus service and a small client program. This would remove the manual parsing that may break and would allow you to use the rich API directly (it grew some features, like spell check).

  10. […] Un nouveau plugin Krunner pour les Debianneux qui vous aide à installer le logiciel que vous souhaitez exécuter, mais qui n’est pas encore installé:  Command Missing Runner […]

  11. […] Jonathan Thomas: “Command Not Found” Plasma Runner (jontheechidna.wordpress.com) […]

  12. […] the one-and-the-same Plasma Runner that I mentioned over a year ago here. Back then QApt hadn’t had a stable release, and I didn’t really have a venue to […]

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

%d bloggers like this: