Massive refactor of initialization script.

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

View file

@ -1,71 +1,59 @@
# Check for updates on initial load... # Initialization script of oh-my-zsh
if [ "$DISABLE_AUTO_UPDATE" != "true" ]; then #
/usr/bin/env ZSH=$ZSH DISABLE_UPDATE_PROMPT=$DISABLE_UPDATE_PROMPT zsh $ZSH/tools/check_for_upgrade.sh # Skip to the bottom of the file to see how oh-my-zsh loads
fi # its awesomeness at a single glance.
# Initializes Oh My Zsh check_for_updates() {
if [ "$DISABLE_AUTO_UPDATE" != "true" ]; then
# add a function path /usr/bin/env ZSH=$ZSH DISABLE_UPDATE_PROMPT=$DISABLE_UPDATE_PROMPT \
fpath=($ZSH/functions $ZSH/completions $fpath) zsh -f $ZSH/tools/check_for_upgrade.sh
# 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.
for plugin ($plugins); do
if is_plugin $ZSH_CUSTOM $plugin; then
fpath=($ZSH_CUSTOM/plugins/$plugin $fpath)
elif is_plugin $ZSH $plugin; then
fpath=($ZSH/plugins/$plugin $fpath)
fi fi
done }
# Figure out the SHORT hostname # Resolves plugin names to their respective paths.
if [ -n "$commands[scutil]" ]; then # 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
plugin_path="plugins/$plugin/$plugin.plugin.zsh"
for zsh_path in $ZSH_CUSTOM $ZSH; do
if [ -f "$zsh_path/$plugin_path" ]; then
ZSH_PLUGIN_PATHS+="$zsh_path/$plugin_path"
break
fi
done
done
}
initialize_completions() {
# Figure out the SHORT hostname
if [ -n "$commands[scutil]" ]; then
# OS X # OS X
SHORT_HOST=$(scutil --get ComputerName) SHORT_HOST=$(scutil --get ComputerName)
else else
SHORT_HOST=${HOST/.*/} SHORT_HOST=${HOST/.*/}
fi
# Save the location of the current completion dump file.
ZSH_COMPDUMP="${ZDOTDIR:-${HOME}}/.zcompdump-${SHORT_HOST}-${ZSH_VERSION}"
# Load and run compinit
autoload -U compinit
compinit -i -d "${ZSH_COMPDUMP}"
# Load all of the plugins that were defined in ~/.zshrc
for plugin ($plugins); do
if [ -f $ZSH_CUSTOM/plugins/$plugin/$plugin.plugin.zsh ]; then
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 fi
done
# Load all of your custom configurations from custom/ # Save the location of the current completion dump file.
for config_file ($ZSH_CUSTOM/*.zsh(N)); do ZSH_COMPDUMP="${ZDOTDIR:-${HOME}}/.zcompdump-${SHORT_HOST}-${ZSH_VERSION}"
source $config_file
done # plugins need to be added to the functions path before compinit
unset config_file fpath=($ZSH_PLUGIN_PATHS $fpath)
autoload -U compinit
compinit -i -d "${ZSH_COMPDUMP}"
}
source_files() {
for file in $@; do
source $file
done
}
load_lib_files() { source_files $ZSH/lib/*.zsh }
load_plugins() { source_files $ZSH_PLUGIN_PATHS }
load_customizations() { source_files $ZSH_CUSTOM/*.zsh }
# 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