Hacker News new | ask | show | jobs
by amluto 801 days ago
> PackageKit-command-not-found

This one is so pathetically slow on Fedora that I find it counterproductive. Also, at least as of a year or two ago (I haven’t checked since then), PackageKit maintained its own, large, cache, thus wasting a surprising amount of space in /var.

1 comments

It depends. It's better than nothing that can be ^C'ed.

Here's a naive, partial implementation that runs in <500 ms so long as there's an existing dnf cache:

   command_not_found_handle() {
    local pkgs
    readarray pkgs < <(dnf rq --whatprovides "$1" -C --qf '%{name}\n' 2>/dev/null | sed '/^$/d' | sort -uVr)
    if (( ! "${#pkgs[@]}" )); then
      echo >&2 'Command not found and no package provides it according to the dnf cache'
      return
    fi
    echo >&2 'Command not found, but offered via the following command(s):'
    pkgs=("${pkgs[@]/#/    dnf install }")
    echo >&2 " ${pkgs[@]}"
  }