zshrc: Give check_com a -g option to test for global aliases, too.
authorFrank Terbeck <ft@bewatermyfriend.org>
Sun, 7 Jun 2009 10:56:37 +0000 (12:56 +0200)
committerFrank Terbeck <ft@bewatermyfriend.org>
Sun, 7 Jun 2009 10:56:37 +0000 (12:56 +0200)
debian/changelog
etc/zsh/zshrc

index f742e72..47e3b9a 100644 (file)
@@ -5,12 +5,13 @@ grml-etc-core (0.3.73) UNRELEASED; urgency=low
     to hang forever. Reported by Rasmus Steinke.
   * zshrc: Fix problems related to TERM=mostlike in zshrc. Again reported by
     Rasmus Steinke.
+  * zshrc: Give check_com a -g option to test for global aliases, too.
 
   [ Michael Prokop ]
   * zshrc: add deborphan, pal and hnb to compdef _gnu_generic. Thanks for
     the suggestion to Carsten Hey.
 
- -- Michael Prokop <mika@grml.org>  Fri, 05 Jun 2009 09:35:58 +0200
+ -- Frank Terbeck <ft@grml.org>  Sun, 07 Jun 2009 12:55:15 +0200
 
 grml-etc-core (0.3.72) unstable; urgency=low
 
index 30922f7..06523f6 100644 (file)
@@ -332,14 +332,20 @@ fi # GRML_WARN_SKEL
 # this function checks if a command exists and returns either true
 # or false. This avoids using 'which' and 'whence', which will
 # avoid problems with aliases for which on certain weird systems. :-)
+# Usage: check_com [-c|-g] word
+#   -c  only checks for external commands
+#   -g  does the usual tests and also checks for global aliases
 check_com() {
-    local -i comonly
+    local -i comonly gatoo
 
     if [[ ${1} == '-c' ]] ; then
         (( comonly = 1 ))
         shift
+    elif [[ ${1} == '-g' ]] ; then
+        (( gatoo = 1 ))
     else
         (( comonly = 0 ))
+        (( gatoo = 0 ))
     fi
 
     if (( ${#argv} != 1 )) ; then
@@ -360,6 +366,10 @@ check_com() {
         return 0
     fi
 
+    if (( gatoo > 0 )) && [[ -n ${galiases[$1]} ]] ; then
+        return 0
+    fi
+
     return 1
 }