wrote this few years ago
needs to be customized for your own system
$ file.webm
bash: command not found: file.webm
Playing: file.webm
...
$ fish
bash: command not found: fish
fish may be found in the following packages:
community/fish 2.7.1-1 /usr/bin/fish
$ lsd
bash: command not found: lsd
Did you mean: ldd, ld, ls
_mime_run() {
local prog
[[ -f "$1" ]] || return
case "$(file -b --mime-type -- "$1")" in
video/*|audio/*) prog=mpv ;;
image/*) prog=feh ;;
application/pdf) prog=mupdf ;;
text/*) prog="${PAGER}" ;;
*) return 1
esac
"${prog}" "$@"
}
# based on pkgfile's /usr/share/doc/pkgfile/command-not-found.bash
_pacman_check() {
type pkgfile &>/dev/null || return
local pkgs
mapfile -t pkgs < <(pkgfile -bv -- "$1" 2>/dev/null)
(( ${#pkgs[*]} )) || return
printf "%s may be found in the following packages:\n" "$1"
printf " %s\n" "${pkgs[@]}"
}
_spell_check() {
[[ -f ${BASH_ASPELL_DICT} ]] || return
type aspell &>/dev/null || return
aspell -d "${BASH_ASPELL_DICT}" -a --sug-mode=fast <<< "$1" 2>&1 | \
sed -n 's/^&.*: /Did you mean: /p'
}
command_not_found_handle() {
echo "$(basename -- "${SHELL}"): command not found: $1" 1>&2
_mime_run "$@" && return
_pacman_check "$@" && return
_spell_check "$@" && return
}
BASH_ASPELL_DICT=~/.cache/bash-aspell-dict
dict for spell check needs to be generated
while read -d: dir; do
for file in "${dir}"/*; do
[[ -x ${file} ]] || continue
basename -- "${file}"
done
done <<<"${PATH}" | \
aspell --lang=en --dont-validate-words create master "${BASH_ASPELL_DICT}"