prezto_config/modules/helper/init.zsh

33 lines
759 B
Bash
Raw Normal View History

2012-09-09 00:47:57 +02:00
#
# Defines helper functions.
#
# Authors:
# Sorin Ionescu <sorin.ionescu@gmail.com>
#
2012-09-09 01:08:54 +02:00
# Checks if a file can be autoloaded by trying to load it in a subshell.
function is-autoloadable {
( unfunction $1 ; autoload -U +X $1 ) &> /dev/null
2012-09-09 00:47:57 +02:00
}
# Checks a name if it is a command, function, or alias.
function is-callable {
(( $+commands[$1] )) || (( $+functions[$1] )) || (( $+aliases[$1] ))
}
2012-09-09 01:08:54 +02:00
# 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]|)) ]]
}
2012-09-09 00:47:57 +02:00
# Prints the first non-empty string in the arguments array.
function coalesce {
for arg in $argv; do
print "$arg"
return 0
done
return 1
}