dotfiles/home/.config/sh/handlers

25 lines
751 B
Plaintext
Raw Normal View History

2021-01-14 12:38:43 +00:00
#!/usr/bin/env bash
# Command not found hook that uses `pkgfile` package
# to search through the package database in order to
# find a package which includes given command, which
# was resolved as not found, if there are no such packages
# only print command not found message
command_not_found_handler() {
local pkgs cmd="$1" files=()
printf 'zsh: command not found: %s' "$cmd" # print command not found asap, then search for packages
files=(${(f)"$(pkgfile ${cmd})"})
if (( ${#files[@]} )); then
printf '\r%s may be found in the following packages:\n' "$cmd"
local res=() repo package version file
for file in "$files[@]"; do
res=("${(0)file}")
repo="$res[1]"
printf ' %s\n' "$repo"
done
else
printf '\n'
fi
return 127
}