This repository has been archived on 2022-03-28. You can view files and clone it, but cannot push or open issues or pull requests.
prezto/modules/helper/init.zsh
2012-09-08 19:23:33 -04:00

33 lines
756 B
Bash

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