Refactors theme loading.

In response to #2113.
This commit is contained in:
LFDM 2014-01-04 17:58:29 +01:00
commit 338141784a
2 changed files with 51 additions and 26 deletions

View file

@ -32,15 +32,6 @@ else
SCREEN_NO="" SCREEN_NO=""
fi fi
# Apply theming defaults
PS1="%n@%m:%~%# "
# git theming default: Variables for theming the git info prompt
ZSH_THEME_GIT_PROMPT_PREFIX="git:(" # Prefix at the very beginning of the prompt, before the branch name
ZSH_THEME_GIT_PROMPT_SUFFIX=")" # At the very end of the prompt
ZSH_THEME_GIT_PROMPT_DIRTY="*" # Text to display if the branch is dirty
ZSH_THEME_GIT_PROMPT_CLEAN="" # Text to display if the branch is clean
# Setup the prompt with pretty colors # Setup the prompt with pretty colors
setopt prompt_subst setopt prompt_subst

View file

@ -67,22 +67,56 @@ for config_file ($ZSH_CUSTOM/*.zsh(N)); do
done done
unset config_file unset config_file
# Load the theme # Sources ZSH_THEME
if [ "$ZSH_THEME" = "random" ]; then # Does nothing if ZSH_THEME is an empty string or unset
themes=($ZSH/themes/*zsh-theme) _source_zsh_theme() {
N=${#themes[@]} if [ "$ZSH_THEME" = "random" ]; then
((N=(RANDOM%N)+1)) themes=($ZSH/themes/*zsh-theme)
RANDOM_THEME=${themes[$N]} N=${#themes[@]}
source "$RANDOM_THEME" ((N=(RANDOM%N)+1))
echo "[oh-my-zsh] Random theme '$RANDOM_THEME' loaded..." RANDOM_THEME=${themes[$N]}
else source "$RANDOM_THEME"
if [ ! "$ZSH_THEME" = "" ]; then echo "[oh-my-zsh] Random theme '$RANDOM_THEME' loaded..."
if [ -f "$ZSH_CUSTOM/$ZSH_THEME.zsh-theme" ]; then elif; then
source "$ZSH_CUSTOM/$ZSH_THEME.zsh-theme" if [ ! "$ZSH_THEME" = "" ]; then
elif [ -f "$ZSH_CUSTOM/themes/$ZSH_THEME.zsh-theme" ]; then if [ -f "$ZSH_CUSTOM/$ZSH_THEME.zsh-theme" ]; then
source "$ZSH_CUSTOM/themes/$ZSH_THEME.zsh-theme" source "$ZSH_CUSTOM/$ZSH_THEME.zsh-theme"
else elif [ -f "$ZSH_CUSTOM/themes/$ZSH_THEME.zsh-theme" ]; then
source "$ZSH/themes/$ZSH_THEME.zsh-theme" source "$ZSH_CUSTOM/themes/$ZSH_THEME.zsh-theme"
else
source "$ZSH/themes/$ZSH_THEME.zsh-theme"
fi
fi fi
fi fi
fi }
_default_theming() {
echo "Falling back to default theming"
# default prompt
PS1="%n@%m:%~%# "
# default variables for theming the git info prompt
ZSH_THEME_GIT_PROMPT_PREFIX="git:(" # Prefix at the very beginning of the prompt, before the branch name
ZSH_THEME_GIT_PROMPT_SUFFIX=")" # At the very end of the prompt
ZSH_THEME_GIT_PROMPT_DIRTY="*" # Text to display if the branch is dirty
ZSH_THEME_GIT_PROMPT_CLEAN="" # Text to display if the branch is clean
}
# Tries to source a theme given as ZSH_THEME.
# If ZSH_THEME is not set, nothing is done at all. This is
# to enable users do circumvent the theming of oh-my-zsh
# on purpose.
# If ZSH_THEME contains an invalid theme string, a fallback
# is provided.
# Takes an argument to provide a new value fo ZSH_THEME
# before loading it.
# Example to load a random theme::
# load_zsh_theme random
# Example to load whatever ZSH_THEME currently is:
# load_zsh_theme
load_zsh_theme() {
if [ ! "$1" = '' ]; then; ZSH_THEME="$1"; fi
_source_zsh_theme || _default_theming
}
load_zsh_theme