From 3fb01c95317bd64a9fb2f15bedb048af886f2e2f Mon Sep 17 00:00:00 2001 From: Simon Gomizelj Date: Mon, 28 Nov 2011 12:17:02 -0500 Subject: [PATCH] If pkgfile is installed, add a "command not found" hook. This hook is of better quality than the one that's pre-packaged with pkgtools (it won't run when a command is part of a pipe or subshell). I should see about getting this hook accepted in pkgtools. --- lib/notfound.zsh | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) create mode 100644 lib/notfound.zsh diff --git a/lib/notfound.zsh b/lib/notfound.zsh new file mode 100644 index 000000000..6a2afb5e9 --- /dev/null +++ b/lib/notfound.zsh @@ -0,0 +1,20 @@ +if [[ -x /usr/bin/pkgfile ]]; then + command_not_found_handler() { + local pkg p + local pid ppid pgrp session tty_nr tpgid + + # double check pkgfile exists + [[ ! -x /usr/bin/pkgfile ]] && return 127 + + # do not run when within a pipe or subshell + [[ ! -t 1 ]] && return 127 + read pid cmd state ppid pgrp session tty_nr tpgid rest < /proc/self/stat + [[ $$ -eq $tpgid ]] && return 127 + + pkg=$(pkgfile -b -v -- $1) + if [[ -z $pkg ]] && return 127 + + echo "The command \"$1\" can be found in the following packages:" + for p in $pkg; echo " $p" + } +fi