You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
32 lines
727 B
32 lines
727 B
#
|
|
# Defines helper functions.
|
|
#
|
|
# Authors:
|
|
# Sorin Ionescu <sorin.ionescu@gmail.com>
|
|
#
|
|
|
|
# Checks if a file can be autoloaded by trying to load it in a subshell.
|
|
is-autoloadable() {
|
|
( unfunction $1 ; autoload -U +X $1 ) &> /dev/null
|
|
}
|
|
|
|
# Checks if a name is a command, function, or alias.
|
|
is-callable() {
|
|
(( $+commands[$1] )) || (( $+functions[$1] )) || (( $+aliases[$1] ))
|
|
}
|
|
|
|
# Checks a boolean variable for "true".
|
|
# Case insensitive: "1", "y", "yes", "t", "true", "o", and "on".
|
|
is-true() {
|
|
[[ -n "$1" && "$1" == (1|[Yy]([Ee][Ss]|)|[Tt]([Rr][Uu][Ee]|)|[Oo]([Nn]|)) ]]
|
|
}
|
|
|
|
# Prints the first non-empty string in the arguments array.
|
|
coalesce() {
|
|
for arg in $argv; do
|
|
print "$arg"
|
|
return 0
|
|
done
|
|
return 1
|
|
}
|