mirror of
https://github.com/ItsDrike/dotfiles.git
synced 2024-12-26 05:04:34 +00:00
Add support for ubuntu command-not-found handler
This commit is contained in:
parent
7544525472
commit
edc7a37a1e
|
@ -1,10 +1,11 @@
|
|||
#!/usr/bin/env bash
|
||||
|
||||
if command -v pkgfile > /dev/null; then
|
||||
# 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
|
||||
# to search through the package index in order to find
|
||||
# a package which includes given command, which was resolved
|
||||
# and 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
|
||||
|
@ -22,3 +23,21 @@ command_not_found_handler() {
|
|||
fi
|
||||
return 127
|
||||
}
|
||||
elif [ -x /usr/lib/command-not-found -o -x /usr/share/command-not-found/command-not-found ]; then
|
||||
# Ubuntu handle for bash default command-not-found
|
||||
# it works similarely to the above arch alternative,
|
||||
# this is a clone of the original bash implementation
|
||||
function command_not_found_handle {
|
||||
# check because cmd not found could've been removed in the meantime
|
||||
if [ -x /usr/lib/command-not-found ]; then
|
||||
/usr/lib/command-not-found -- "$1"
|
||||
return $?
|
||||
elif [ -x /usr/share/command-not-found/command-not-found ]; then
|
||||
/usr/share/command-not-found/command-not-found -- "$1"
|
||||
return $?
|
||||
else
|
||||
printf "%s: command not found\n" "$1" >&2
|
||||
return 127
|
||||
fi
|
||||
}
|
||||
fi
|
||||
|
|
Loading…
Reference in a new issue