💾 Archived View for perso.pw › blog › articles › openbsd-command-not-found.gmi captured on 2023-07-10 at 13:53:10. Gemini links have been rewritten to link to archived content
⬅️ Previous capture (2023-05-24)
-=-=-=-=-=-=-
On many Linux systems, there is a special program run by the shell (configured by default) that will tell you which package provide a command you tried to run but is not available in $PATH. Let's do the same for OpenBSD!
We will need to install the package pkglocate to find binaries.
# pkg_add pkglocate
We will also need a file /usr/local/bin/command-not-found executable with this content:
#!/bin/sh CMD="$1" RESULT=$(pkglocate */bin/${CMD} */sbin/${CMD} | cut -d ':' -f 1) if [ -n "$RESULT" ] then echo "The following package(s) contain program ${CMD}" for result in $RESULT do echo " - $result" done else echo "pkglocate didn't find a package providing program ${CMD}" fi
Now, we need to configure the shell to run this command when it detects an error corresponding to an unknown command. This is possible with bash, zsh or fish at least.
Let's go with bash, add this to your bash configuration file
command_not_found_handle() { /usr/local/bin/command-not-found "$1" }
function fish_command_not_found /usr/local/bin/command-not-found $argv[1] end
function command_not_found_handler() { /usr/local/bin/command-not-found "$1" }
Now that you configured your shell correctly, if you run a command in your shell that isn't available in your PATH, you may have either a success with a list of packages giving the command or that the command can't be found in any package (unlucky).
This is a successful output that found the program we were trying to run.
$ pup The following package(s) contain program pup - pup-0.4.0p0
This is a result showing that no package found a program named "steam".
$ steam pkglocate didn't find a package providing program steam