mirror of
https://github.com/ohmyzsh/ohmyzsh.git
synced 2026-02-13 03:01:32 +01:00
Massive refactor of initialization script.
This commit is contained in:
parent
945fdc5ef6
commit
74349a190d
1 changed files with 61 additions and 68 deletions
131
oh-my-zsh.sh
131
oh-my-zsh.sh
|
|
@ -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
|
||||||
|
fi
|
||||||
# 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.
|
||||||
for plugin ($plugins); do
|
# If a custom plugin is defined, the default plugin
|
||||||
if is_plugin $ZSH_CUSTOM $plugin; then
|
# won't be added to the plugin_paths.
|
||||||
fpath=($ZSH_CUSTOM/plugins/$plugin $fpath)
|
find_plugin_paths() {
|
||||||
elif is_plugin $ZSH $plugin; then
|
ZSH_PLUGIN_PATHS=()
|
||||||
fpath=($ZSH/plugins/$plugin $fpath)
|
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
|
||||||
|
SHORT_HOST=$(scutil --get ComputerName)
|
||||||
|
else
|
||||||
|
SHORT_HOST=${HOST/.*/}
|
||||||
fi
|
fi
|
||||||
done
|
|
||||||
|
|
||||||
# Figure out the SHORT hostname
|
# Save the location of the current completion dump file.
|
||||||
if [ -n "$commands[scutil]" ]; then
|
ZSH_COMPDUMP="${ZDOTDIR:-${HOME}}/.zcompdump-${SHORT_HOST}-${ZSH_VERSION}"
|
||||||
# OS X
|
|
||||||
SHORT_HOST=$(scutil --get ComputerName)
|
|
||||||
else
|
|
||||||
SHORT_HOST=${HOST/.*/}
|
|
||||||
fi
|
|
||||||
|
|
||||||
# Save the location of the current completion dump file.
|
# plugins need to be added to the functions path before compinit
|
||||||
ZSH_COMPDUMP="${ZDOTDIR:-${HOME}}/.zcompdump-${SHORT_HOST}-${ZSH_VERSION}"
|
fpath=($ZSH_PLUGIN_PATHS $fpath)
|
||||||
|
|
||||||
# Load and run compinit
|
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
|
done
|
||||||
elif [ -f $ZSH/plugins/$plugin/$plugin.plugin.zsh ]; then
|
}
|
||||||
source $ZSH/plugins/$plugin/$plugin.plugin.zsh
|
|
||||||
fi
|
|
||||||
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
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue