Run commands from toolbox / distrobox only if missing

I was bored switching to/from ArchLinux/Fedora with toolbox/distrobox

Exemple: I need an ArchLinux package, I enter distrobox, I work on the command line and then I want to launch an application like org.gnome.geary for exemple: flatpak command not found.

Normal, I’m in the toolbox container, not in Silverblue.

After thinking to the issue, I remembered command-not-found package, how does it work ?

I now have this in my Bash configuration:


command_not_found_handle() {
    echo $@|grep 'pacman' >/dev/null 2>&1
    if (( $? == 0 ))
        distrobox-enter -n arch -e sudo $@
        distrobox-enter -n arch -e $@
    return $?

Example for toolbox:


command_not_found_handle() {
    toolbox run $@
    return $?

Only thing missing is completion.