forked from adoyle-h/lobash
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathhas.s.bash
30 lines (28 loc) · 953 Bytes
/
has.s.bash
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
# ---
# Category: Condition
# Since: 0.3.0
# Usage: l.has.s <condition> <what>
# Description: Echo `true` or `false` to indicate that command/function/alias/keyword/builtin or anything existed.
# Description: `<condition>` Valid value: `command`, `function`, `alias`, `keyword`, `builtin`, `the`
# ---
l.has.s() {
local condition="$1"
local value="$2"
case "$condition" in
command)
[[ -x "$(command -v "$value")" ]] && echo true || echo false;;
function)
[[ $(type -t "$value") == function ]] && echo true || echo false;;
alias)
[[ $(type -t "$value") == alias ]] && echo true || echo false;;
keyword)
[[ $(type -t "$value") == keyword ]] && echo true || echo false;;
builtin)
[[ $(type -t "$value") == builtin ]] && echo true || echo false;;
the)
type -t "$value" >/dev/null && echo true || echo false;;
*)
echo "Invalid Condition: $condition" >&2
return 3;;
esac
}