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 ( 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"). # Checks boolean variable for "true" (case insensitive "1", "y", "yes", "t", "true", "o", and "on").
function is-true { function is-true {
[[ -n "$1" && "$1" == (1|[Yy]([Ee][Ss]|)|[Tt]([Rr][Uu][Ee]|)|[Oo]([Nn]|)) ]] [[ -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' zstyle ':omz:prompt' theme 'off'
fi 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 Zsh functions.
autoload -Uz age autoload -Uz age
autoload -Uz zargs autoload -Uz zargs
autoload -Uz zcalc autoload -Uz zcalc
autoload -Uz zmv autoload -Uz zmv
# Source modules defined in ~/.zshrc. # Source files (the order matters).
for omodule in "$omodules[@]"; do source "${0:h}/helper.zsh"
if [[ ! -d "${0:h}/modules/$omodule" ]]; then
print "omz: no such module: $omodule" >&2
fi
if [[ -f "${0:h}/modules/$omodule/init.zsh" ]]; then # Get enabled modules.
source "${0:h}/modules/$omodule/init.zsh" zstyle -a ':omz:module' enable 'omodules'
fi
if (( $? == 0 )); then # Source modules defined in ~/.zshrc.
zstyle ":omz:module:$omodule" enable 'yes' omodload "$omodules[@]"
fi
done
unset omodule omodules
# Autoload Oh My Zsh functions. # Add themes to fpath.
for fdir in "$fpath[@]"; do fpath=(${0:h}/themes/*(/FN) $fpath)
if [[ "$fdir" == ${0:h}/(|*/)functions ]]; then
for func in $fdir/[^_.]*(N.:t); do
autoload -Uz $func
done
fi
done
unset fdir func
# 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
# Load and run the prompt theming system. # Load and run the prompt theming system.
autoload -Uz promptinit && promptinit autoload -Uz promptinit && promptinit
@ -87,6 +49,14 @@ else
fi fi
unset prompt_argv 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. # Compile the completion dump, to increase startup speed.
dump_file="$HOME/.zcompdump" dump_file="$HOME/.zcompdump"
if [[ "$dump_file" -nt "${dump_file}.zwc" || ! -f "${dump_file}.zwc" ]]; then if [[ "$dump_file" -nt "${dump_file}.zwc" || ! -f "${dump_file}.zwc" ]]; then

@ -11,6 +11,9 @@ if [[ "$TERM" == 'dumb' ]]; then
return 1 return 1
fi 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 COMPLETE_IN_WORD # Complete from both ends of a word.
setopt ALWAYS_TO_END # Move cursor to the end of a completed 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. setopt PATH_DIRS # Perform path search even on command names with slashes.

Loading…
Cancel
Save