zshrc: check_com() fixed and zshified
authorThilo Six <tech@xk2c.de>
Sat, 30 Apr 2016 11:39:05 +0000 (13:39 +0200)
committerMichael Prokop <mika@grml.org>
Sat, 30 Apr 2016 21:30:55 +0000 (23:30 +0200)
* FIX: in the elif a shift was missing
* MOD: use '(( ${+' instead of '[[ -n ${'
  One thing though: I tried to verify since when Zsh supports that.
  Currently i do not know where to get that from.
* FIX: add -g to help message

etc/zsh/zshrc

index 14cc648..c03b614 100644 (file)
@@ -450,36 +450,35 @@ fi
 check_com() {
     emulate -L zsh
     local -i comonly gatoo
+    comonly=0
+    gatoo=0
 
     if [[ $1 == '-c' ]] ; then
-        (( comonly = 1 ))
-        shift
+        comonly=1
+        shift 1
     elif [[ $1 == '-g' ]] ; then
-        (( gatoo = 1 ))
-    else
-        (( comonly = 0 ))
-        (( gatoo = 0 ))
+        gatoo=1
+        shift 1
     fi
 
     if (( ${#argv} != 1 )) ; then
-        printf 'usage: check_com [-c] <command>\n' >&2
+        printf 'usage: check_com [-c|-g] <command>\n' >&2
         return 1
     fi
 
     if (( comonly > 0 )) ; then
-        [[ -n ${commands[$1]}  ]] && return 0
+        (( ${+commands[$1]}  )) && return 0
         return 1
     fi
 
-    if   [[ -n ${commands[$1]}    ]] \
-      || [[ -n ${functions[$1]}   ]] \
-      || [[ -n ${aliases[$1]}     ]] \
-      || [[ -n ${reswords[(r)$1]} ]] ; then
-
+    if     (( ${+commands[$1]}    )) \
+        || (( ${+functions[$1]}   )) \
+        || (( ${+aliases[$1]}     )) \
+        || (( ${+reswords[(r)$1]} )) ; then
         return 0
     fi
 
-    if (( gatoo > 0 )) && [[ -n ${galiases[$1]} ]] ; then
+    if (( gatoo > 0 )) && (( ${+galiases[$1]} )) ; then
         return 0
     fi