60 lines
871 B
Bash
60 lines
871 B
Bash
|
# vim: ft=zsh
|
||
|
# Modules
|
||
|
|
||
|
function msg {
|
||
|
if ! (( flag_quiet )); then
|
||
|
printf '%s\n' "$*"
|
||
|
fi
|
||
|
}
|
||
|
|
||
|
function err { msg "$*" >&2; }
|
||
|
|
||
|
function modpath {
|
||
|
case $1 in
|
||
|
(=) ZSHRC_MODPATH=( "$@" );;
|
||
|
(*) ZSHRC_MODPATH+=( "$@" );;
|
||
|
esac
|
||
|
|
||
|
export ZSHRC_MODPATH
|
||
|
}
|
||
|
|
||
|
function use {
|
||
|
declare flag_nofail flag_quiet mname m_nofirst
|
||
|
|
||
|
while (( $# )); do
|
||
|
case $1 in
|
||
|
(-n) flag_nofail=1;;
|
||
|
(-q) flag_quiet=1;;
|
||
|
(--) shift; break;;
|
||
|
(*) break;;
|
||
|
esac
|
||
|
shift
|
||
|
done
|
||
|
|
||
|
printf '[zshrc] Loading modules: '
|
||
|
for mname in $@; do
|
||
|
if ! (( m_nofirst )); then
|
||
|
printf '%s' $mname
|
||
|
else
|
||
|
printf ', %s' $mname
|
||
|
fi
|
||
|
|
||
|
for p in $ZSHRC_MODPATH; do
|
||
|
if [[ -f $p/$mname ]]; then
|
||
|
if ! source $p/$mname; then
|
||
|
printf '(fail)'
|
||
|
fi
|
||
|
else
|
||
|
printf '(not found)'
|
||
|
fi
|
||
|
done
|
||
|
|
||
|
m_nofirst=1
|
||
|
done
|
||
|
|
||
|
printf '\n'
|
||
|
}
|
||
|
|
||
|
# Default ZSHRC_MODPATH
|
||
|
modpath "$HOME/.config/zsh.d/modules"
|