mirror of
https://github.com/ItsDrike/dotfiles.git
synced 2024-11-14 12:17:17 +00:00
25 lines
751 B
Plaintext
25 lines
751 B
Plaintext
|
#!/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
|
||
|
}
|