1
0
mirror of https://github.com/dcarrillo/prezto.git synced 2025-06-14 19:31:43 +00:00

[#245] Convert helper into a module

This commit is contained in:
Sorin Ionescu
2012-09-08 18:47:57 -04:00
parent 737d0e51ee
commit e5e26eccff
6 changed files with 112 additions and 97 deletions

32
modules/helper/init.zsh Normal file
View File

@ -0,0 +1,32 @@
#
# 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
}

View File

@ -8,6 +8,9 @@
# http://i.imgur.com/4CeOj.png
#
# Load dependencies.
pmodload 'helper'
function prompt_sorin_precmd {
setopt LOCAL_OPTIONS
unsetopt XTRACE KSH_ARRAYS

View File

@ -11,6 +11,9 @@
# Sorin Ionescu <sorin.ionescu@gmail.com>
#
# Load dependencies.
pmodload 'helper'
# Return if requirements are not found.
if (( ! $+commands[ssh-agent] )); then
return 1

View File

@ -8,7 +8,7 @@
#
# Load dependencies.
pmodload 'spectrum'
pmodload 'helper' 'spectrum'
# Correct commands.
setopt CORRECT