zshrc: add a handler that uses debian's command-not-found package v0.3.66
authorFrank Terbeck <ft@bewatermyfriend.org>
Fri, 3 Apr 2009 19:23:52 +0000 (21:23 +0200)
committerFrank Terbeck <ft@bewatermyfriend.org>
Sat, 4 Apr 2009 09:53:11 +0000 (11:53 +0200)
That package allows the user to get information with what package
a certain command can be installed. AFAIK that package is only
available on Debian based systems. Therefore disabled by default.

debian/changelog
etc/zsh/zshrc

index 49a97ad..dbeee10 100644 (file)
@@ -6,8 +6,10 @@ grml-etc-core (0.3.66) unstable; urgency=low
     exists.
   * zshrc: add commit-to-history widget, that allows users to add
     command lines to zsh's history without executing [Closes: issue407]
+  * zshrc: add a handler that uses debian's command-not-found package
+    if an external command could not be found. [Closes: issue564]
 
- -- Frank Terbeck <ft@grml.org>  Sat, 04 Apr 2009 11:35:06 +0200
+ -- Frank Terbeck <ft@grml.org>  Sat, 04 Apr 2009 11:52:50 +0200
 
 grml-etc-core (0.3.65) unstable; urgency=low
 
index e1e8a13..8a836cd 100644 (file)
@@ -230,6 +230,8 @@ zrcautoload is-at-least || is-at-least() { return 1 }
 NOCOR=${NOCOR:-0}
 NOMENU=${NOMENU:-0}
 NOPRECMD=${NOPRECMD:-0}
+COMMAND_NOT_FOUND=${COMMAND_NOT_FOUND:-0}
+GRML_ZSH_CNF_HANDLER=${GRML_ZSH_CNF_HANDLER:-/usr/share/command-not-found/command-not-found}
 BATTERY=${BATTERY:-0}
 GRMLSMALL_SPECIFIC=${GRMLSMALL_SPECIFIC:-1}
 GRML_ALWAYS_LOAD_ALL=${GRML_ALWAYS_LOAD_ALL:-0}
@@ -1913,6 +1915,19 @@ fi
 
 # }}}
 
+# command not found handling {{{
+
+(( ${COMMAND_NOT_FOUND} == 1 )) &&
+function command_not_found_handler() {
+    setopt localoptions no_sh_wordsplit
+    if [[ -x ${GRML_ZSH_CNF_HANDLER} ]] ; then
+        ${GRML_ZSH_CNF_HANDLER} $1
+    fi
+    return 1
+}
+
+# }}}
+
 # {{{ set prompt
 if zrcautoload promptinit && promptinit 2>/dev/null ; then
     promptinit # people should be able to use their favourite prompt
@@ -2201,6 +2216,11 @@ the zsh yet. :)
   "NOTITLE=1  zsh" => disable setting the title of xterms without disabling
                       preexec() and precmd() completely
   "BATTERY=1  zsh" => activate battery status (via acpi) on right side of prompt
+  "COMMAND_NOT_FOUND=1 zsh"
+                   => Enable a handler if an external command was not found
+                      The command called in the handler can be altered by setting
+                      the GRML_ZSH_CNF_HANDLER variable, the default is:
+                      "/usr/share/command-not-found/command-not-found"
 
 A value greater than 0 is enables a feature; a value equal to zero
 disables it. If you like one or the other of these settings, you can