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:
32
modules/helper/init.zsh
Normal file
32
modules/helper/init.zsh
Normal 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
|
||||
}
|
||||
|
@ -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
|
||||
|
@ -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
|
||||
|
@ -8,7 +8,7 @@
|
||||
#
|
||||
|
||||
# Load dependencies.
|
||||
pmodload 'spectrum'
|
||||
pmodload 'helper' 'spectrum'
|
||||
|
||||
# Correct commands.
|
||||
setopt CORRECT
|
||||
|
Reference in New Issue
Block a user