summaryrefslogtreecommitdiff
path: root/etc/functions/check_com
blob: 21de46624aa0dc0400dffeee43b7b9dbb6a1b8f9 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
## vim:ft=zsh
## Check for a command/function
## Usage: check_com [-c] <command>
## 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