2012-07-20 09:35:41 -07:00
|
|
|
#!/bin/zsh
|
|
|
|
# vim: ft=zsh
|
|
|
|
# Helper functions for the init files
|
|
|
|
# Eryn Wells <eryn@erynwells.me>
|
|
|
|
|
|
|
|
|
|
|
|
# Print prettier, more uniform messages
|
|
|
|
function print_msg { print -P "%F{$1}==>%f $2" }
|
|
|
|
function print_info { print_msg 'blue' "$@" }
|
|
|
|
function print_error { print_msg 'red' "$@" }
|
|
|
|
|
2012-08-07 11:19:43 -07:00
|
|
|
function print_msg_sub { print -P " %F{$1}*%f $2" }
|
|
|
|
function print_info_sub { print_msg_sub 'blue' "$@" }
|
|
|
|
function print_error_sub { print_msg_sub 'error' "$@" }
|
|
|
|
|
|
|
|
# Print if $NOISY is set
|
|
|
|
function print_info_noisy { [ ${NOISY:-0} -ge $1 ] && print_info $@[2,-1] }
|
|
|
|
function print_error_noisy { [ ${NOISY:-0} -ge $1 ] && print_error $@[2,-1] }
|
|
|
|
|
|
|
|
function print_info_sub_noisy { [ ${NOISY:-0} -ge $1 ] && print_info_sub $@[2,-1] }
|
|
|
|
function print_error_sub_noisy { [ ${NOISY:-0} -ge $1 ] && print_error_sub $@[2,-1] }
|
|
|
|
|
2012-11-27 16:24:08 -08:00
|
|
|
function binary_exists { return $(hash $1 1>/dev/null 2>&1) }
|
|
|
|
function binary_not_exists { binary_exists $1; return $(( ! $? )) }
|
2012-11-28 15:23:57 -08:00
|
|
|
|
|
|
|
function load_module {
|
|
|
|
local mod=$1
|
|
|
|
|
|
|
|
local modpath
|
|
|
|
for p in $fpath; do
|
|
|
|
modpath=$p/$1
|
|
|
|
[[ -d $modpath ]] && break
|
|
|
|
modpath=''
|
|
|
|
done
|
|
|
|
|
|
|
|
if [[ -z "$modpath" ]]; then
|
|
|
|
print_error "Couldn't find path to module: $mod"
|
|
|
|
return 1
|
|
|
|
fi
|
|
|
|
|
|
|
|
print_info "Loading module: $mod"
|
|
|
|
for func in `ls $modpath`; do
|
|
|
|
print_info_sub "Loading function: $func"
|
|
|
|
autoload $func
|
|
|
|
done
|
|
|
|
|
|
|
|
return 0
|
|
|
|
}
|