Massive refactor of initialization script.

This commit is contained in:
LFDM 2014-01-04 23:05:25 +01:00
commit 74349a190d

View file

@ -1,42 +1,32 @@
# Check for updates on initial load... # Initialization script of oh-my-zsh
#
# Skip to the bottom of the file to see how oh-my-zsh loads
# its awesomeness at a single glance.
check_for_updates() {
if [ "$DISABLE_AUTO_UPDATE" != "true" ]; then if [ "$DISABLE_AUTO_UPDATE" != "true" ]; then
/usr/bin/env ZSH=$ZSH DISABLE_UPDATE_PROMPT=$DISABLE_UPDATE_PROMPT zsh $ZSH/tools/check_for_upgrade.sh /usr/bin/env ZSH=$ZSH DISABLE_UPDATE_PROMPT=$DISABLE_UPDATE_PROMPT \
zsh -f $ZSH/tools/check_for_upgrade.sh
fi fi
# Initializes Oh My Zsh
# add a function path
fpath=($ZSH/functions $ZSH/completions $fpath)
# Load all of the config files in ~/oh-my-zsh that end in .zsh
# TIP: Add files you don't want in git to .gitignore
for config_file ($ZSH/lib/*.zsh); do
source $config_file
done
# Set ZSH_CUSTOM to the path where your custom config files
# and plugins exists, or else we will use the default custom/
if [[ -z "$ZSH_CUSTOM" ]]; then
ZSH_CUSTOM="$ZSH/custom"
fi
is_plugin() {
local base_dir=$1
local name=$2
test -f $base_dir/plugins/$name/$name.plugin.zsh \
|| test -f $base_dir/plugins/$name/_$name
} }
# Add all defined plugins to fpath. This must be done
# before running compinit. # Resolves plugin names to their respective paths.
# If a custom plugin is defined, the default plugin
# won't be added to the plugin_paths.
find_plugin_paths() {
ZSH_PLUGIN_PATHS=()
for plugin ($plugins); do for plugin ($plugins); do
if is_plugin $ZSH_CUSTOM $plugin; then plugin_path="plugins/$plugin/$plugin.plugin.zsh"
fpath=($ZSH_CUSTOM/plugins/$plugin $fpath) for zsh_path in $ZSH_CUSTOM $ZSH; do
elif is_plugin $ZSH $plugin; then if [ -f "$zsh_path/$plugin_path" ]; then
fpath=($ZSH/plugins/$plugin $fpath) ZSH_PLUGIN_PATHS+="$zsh_path/$plugin_path"
break
fi fi
done done
done
}
initialize_completions() {
# Figure out the SHORT hostname # Figure out the SHORT hostname
if [ -n "$commands[scutil]" ]; then if [ -n "$commands[scutil]" ]; then
# OS X # OS X
@ -48,24 +38,22 @@ fi
# Save the location of the current completion dump file. # Save the location of the current completion dump file.
ZSH_COMPDUMP="${ZDOTDIR:-${HOME}}/.zcompdump-${SHORT_HOST}-${ZSH_VERSION}" ZSH_COMPDUMP="${ZDOTDIR:-${HOME}}/.zcompdump-${SHORT_HOST}-${ZSH_VERSION}"
# Load and run compinit # plugins need to be added to the functions path before compinit
fpath=($ZSH_PLUGIN_PATHS $fpath)
autoload -U compinit autoload -U compinit
compinit -i -d "${ZSH_COMPDUMP}" compinit -i -d "${ZSH_COMPDUMP}"
}
# Load all of the plugins that were defined in ~/.zshrc source_files() {
for plugin ($plugins); do for file in $@; do
if [ -f $ZSH_CUSTOM/plugins/$plugin/$plugin.plugin.zsh ]; then source $file
source $ZSH_CUSTOM/plugins/$plugin/$plugin.plugin.zsh
elif [ -f $ZSH/plugins/$plugin/$plugin.plugin.zsh ]; then
source $ZSH/plugins/$plugin/$plugin.plugin.zsh
fi
done done
}
# Load all of your custom configurations from custom/ load_lib_files() { source_files $ZSH/lib/*.zsh }
for config_file ($ZSH_CUSTOM/*.zsh(N)); do load_plugins() { source_files $ZSH_PLUGIN_PATHS }
source $config_file load_customizations() { source_files $ZSH_CUSTOM/*.zsh }
done
unset config_file
# Sources ZSH_THEME # Sources ZSH_THEME
# Does nothing if ZSH_THEME is an empty string or unset # Does nothing if ZSH_THEME is an empty string or unset
@ -78,16 +66,15 @@ _source_zsh_theme() {
source "$RANDOM_THEME" source "$RANDOM_THEME"
theme_name=$(basename $RANDOM_THEME .zsh-theme) theme_name=$(basename $RANDOM_THEME .zsh-theme)
echo "[oh-my-zsh] Random theme '$theme_name' loaded..." echo "[oh-my-zsh] Random theme '$theme_name' loaded..."
elif; then elif [ ! "$ZSH_THEME" = "" ]; then
if [ ! "$ZSH_THEME" = "" ]; then # custom themes take precedence over built-in themes!
if [ -f "$ZSH_CUSTOM/$ZSH_THEME.zsh-theme" ]; then for zsh_path in $ZSH_CUSTOM $ZSH; do
source "$ZSH_CUSTOM/$ZSH_THEME.zsh-theme" theme_path="themes/$ZSH_THEME.zsh-theme"
elif [ -f "$ZSH_CUSTOM/themes/$ZSH_THEME.zsh-theme" ]; then if [ -f "$zsh_path/$theme_path" ]; then
source "$ZSH_CUSTOM/themes/$ZSH_THEME.zsh-theme" source "$zsh_path/$theme_path"
else break
source "$ZSH/themes/$ZSH_THEME.zsh-theme"
fi
fi fi
done
fi fi
} }
@ -122,4 +109,10 @@ load_zsh_theme() {
_source_zsh_theme || _default_theming _source_zsh_theme || _default_theming
} }
check_for_updates
find_plugin_paths
initialize_completions
load_lib_files
load_plugins
load_customizations
load_zsh_theme load_zsh_theme