diff options
author | Daniel Friesel <derf@derf.homelinux.org> | 2008-10-01 19:40:42 +0200 |
---|---|---|
committer | Daniel Friesel <derf@derf.homelinux.org> | 2008-10-01 19:40:42 +0200 |
commit | cd42e445783c9cac35465127f3b907982baa2e22 (patch) | |
tree | 4731129352fc1a54e120e9c0bd1d35be183234c5 /etc/functions/check_com | |
parent | 9cb72f47b725df585fd4059dcfb34b8ce478f383 (diff) |
Added check_com from the grml zshrc
Diffstat (limited to 'etc/functions/check_com')
-rw-r--r-- | etc/functions/check_com | 31 |
1 files changed, 31 insertions, 0 deletions
diff --git a/etc/functions/check_com b/etc/functions/check_com new file mode 100644 index 0000000..b631e95 --- /dev/null +++ b/etc/functions/check_com @@ -0,0 +1,31 @@ +## vim:ft=zsh +## Check for a command/function +## Taken from the grml zshrc - http://grml.org +local -i comonly + +if [[ ${1} == '-c' ]] ; then + (( comonly = 1 )) + shift +else + (( comonly = 0 )) +fi + +if (( ${#argv} != 1 )) ; then + printf 'usage: check_com [-c] <command>\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 + +return 1 |