#!/bin/sh

FILES=/var/lib/tazpkg/files.list.lzma
LIST=/tmp/command-list.gz
[ -s $FILES ] && [ ! $LIST -nt $FILES ] && unlzma <$FILES | \
grep -E "(: ${PATH//:/|: })" | gzip -9 >$LIST && chmod 666 $LIST

lookup() {
	zcat $LIST 2> /dev/null | grep "/$2$1$" | if read pkg file; then
		cat <<EOT
Command '$1' not found, but can be installed as root with:

tazpkg -gi ${pkg%:}
${2:+$2$1}
EOT
	fi
}

MSG="$(lookup "$1")"
[ "$MSG" ] || MSG="$(lookup "$1" get-)"
echo "${MSG:-${SHELL##*/}: $1: not found}"
