# utility functions # 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() { emulate -L zsh 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 printf 'usage: check_com [-c] \n' >&2 return 1 fi if (( comonly > 0 )) ; then [[ -n ${commands[$1]} ]] && return 0 return 1 fi if [[ -n ${commands[$1]} ]] \ || [[ -n ${functions[$1]} ]] \ || [[ -n ${aliases[$1]} ]] \ || [[ -n ${reswords[(r)$1]} ]] ; then return 0 fi if (( gatoo > 0 )) && [[ -n ${galiases[$1]} ]] ; then return 0 fi return 1 }