1
0
Fork 0

[#23] Add a module loading function

pull/86/head
Sorin Ionescu 13 years ago
parent d3bc869968
commit b34e0502d3

@ -10,6 +10,35 @@ function autoloadable {
( unfunction $1 ; autoload -U +X $1 ) &> /dev/null
}
# Loads Oh My Zsh modules.
function omodload {
local omodule
local OMZ="${funcsourcetrace[1]:h}"
for omodule in "$argv[@]"; do
if [[ ! -d "$OMZ/modules/$omodule" ]]; then
print "omz: no such module: $omodule" >&2
continue
fi
# Add functions and completetions to fpath.
fpath=($OMZ/modules/$omodule/{functions,completions}(/FN) $fpath)
# Autoload module functions.
for func in $OMZ/modules/$omodule/functions/[^_.]*(N.:t); do
autoload -Uz $func
done
if [[ -f "$OMZ/modules/$omodule/init.zsh" ]]; then
source "$OMZ/modules/$omodule/init.zsh"
fi
if (( $? == 0 )); then
zstyle ":omz:module:$omodule" enable 'yes'
fi
done
}
# Checks 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]|)) ]]

@ -19,61 +19,23 @@ if [[ "$TERM" == 'dumb' ]]; then
zstyle ':omz:prompt' theme 'off'
fi
# Get enabled modules.
zstyle -a ':omz:load' module 'omodules'
# Add functions to fpath.
fpath=(
${0:h}/themes/*(/FN)
${omodules:+${0:h}/modules/${^omodules}/{functions,completions}(/FN)}
$fpath
)
# Load and initialize the completion system ignoring insecure directories.
autoload -Uz compinit && compinit -i
# Source files (the order matters).
source "${0:h}/helper.zsh"
# Autoload Zsh functions.
autoload -Uz age
autoload -Uz zargs
autoload -Uz zcalc
autoload -Uz zmv
# Source modules defined in ~/.zshrc.
for omodule in "$omodules[@]"; do
if [[ ! -d "${0:h}/modules/$omodule" ]]; then
print "omz: no such module: $omodule" >&2
fi
if [[ -f "${0:h}/modules/$omodule/init.zsh" ]]; then
source "${0:h}/modules/$omodule/init.zsh"
fi
# Source files (the order matters).
source "${0:h}/helper.zsh"
if (( $? == 0 )); then
zstyle ":omz:module:$omodule" enable 'yes'
fi
done
unset omodule omodules
# Get enabled modules.
zstyle -a ':omz:module' enable 'omodules'
# Autoload Oh My Zsh functions.
for fdir in "$fpath[@]"; do
if [[ "$fdir" == ${0:h}/(|*/)functions ]]; then
for func in $fdir/[^_.]*(N.:t); do
autoload -Uz $func
done
fi
done
unset fdir func
# Source modules defined in ~/.zshrc.
omodload "$omodules[@]"
# Set environment variables for launchd processes.
if [[ "$OSTYPE" == darwin* ]]; then
for env_var in PATH MANPATH; do
launchctl setenv "$env_var" "${(P)env_var}" &!
done
unset env_var
fi
# Add themes to fpath.
fpath=(${0:h}/themes/*(/FN) $fpath)
# Load and run the prompt theming system.
autoload -Uz promptinit && promptinit
@ -87,6 +49,14 @@ else
fi
unset prompt_argv
# Set environment variables for launchd processes.
if [[ "$OSTYPE" == darwin* ]]; then
for env_var in PATH MANPATH; do
launchctl setenv "$env_var" "${(P)env_var}" &!
done
unset env_var
fi
# Compile the completion dump, to increase startup speed.
dump_file="$HOME/.zcompdump"
if [[ "$dump_file" -nt "${dump_file}.zwc" || ! -f "${dump_file}.zwc" ]]; then

@ -11,6 +11,9 @@ if [[ "$TERM" == 'dumb' ]]; then
return 1
fi
# Load and initialize the completion system ignoring insecure directories.
autoload -Uz compinit && compinit -i
setopt COMPLETE_IN_WORD # Complete from both ends of a word.
setopt ALWAYS_TO_END # Move cursor to the end of a completed word.
setopt PATH_DIRS # Perform path search even on command names with slashes.

Loading…
Cancel
Save