zshrc: Give check_com a -g option to test for global aliases, too.
[grml-etc-core.git] / etc / zsh / zshrc
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
 }