Refactor loading of theme into function for reusability

- Make sure to load a new theme after user 'unlikes' a theme
This commit is contained in:
Luke Lee 2011-06-03 19:05:28 -05:00
commit 4a052e88df
2 changed files with 23 additions and 22 deletions

View file

@ -64,7 +64,7 @@ function like_theme() {
theme_name=`get_current_theme`
link_name="$FAVORITE_THEMES_DIR/$theme_name"
if [[ ! -L $link_name ]]; then
if [ ! -L $link_name ]; then
ln -s $RANDOM_THEME $link_name
echo "Added $theme_name to favorites"
else
@ -76,10 +76,10 @@ function unlike_theme() {
theme_name=`get_current_theme`
link_name="$FAVORITE_THEMES_DIR/$theme_name"
if [[ -L $link_name ]]; then
# FIXME: What happens if we remove the last theme we have?
if [ -L $link_name ]; then
rm $link_name
echo "Removed $theme_name from favorites"
load_theme
else
echo "$theme_name isn't a favorite"
fi
@ -100,3 +100,18 @@ function load_random_theme() {
echo "[oh-my-zsh] Random theme '$RANDOM_THEME' loaded..."
export RANDOM_THEME
}
function load_theme() {
if [ "$ZSH_THEME" = "random" ]; then
load_random_theme
elif [ "$ZSH_THEME" = "favorites" ]; then
# Only randomize with liked themes if there are any
if [ `ls $FAVORITE_THEMES_DIR | wc -w` -gt 0 ]; then
load_random_theme $FAVORITE_THEMES_DIR/*zsh-theme
else
load_random_theme
fi
else
source "$ZSH/themes/$ZSH_THEME.zsh-theme"
fi
}

View file

@ -33,27 +33,13 @@ done
# Load all of your custom configurations from custom/
for config_file ($ZSH/custom/*.zsh) source $config_file
export FAVORITE_THEMES_DIR="$ZSH/themes/favorites/"
# Allow users to randomize themes with only their favorites
if [ ! -d $FAVORITE_THEMES_DIR ]; then
mkdir $FAVORITE_THEMES_DIR
fi
# Load the theme
# Check for updates on initial load...
if [ "$ZSH_THEME" = "random" ]; then
load_random_theme
elif [ "$ZSH_THEME" = "favorites" ]; then
# Only randomize with liked themes if there are any
if [ `ls $FAVORITE_THEMES_DIR | wc -w` -gt 0 ]; then
load_random_theme $FAVORITE_THEMES_DIR/*zsh-theme
else
load_random_theme
fi
else
source "$ZSH/themes/$ZSH_THEME.zsh-theme"
# Allow users to randomize themes with only their favorites
if [ ! -d $FAVORITE_THEMES_DIR ]; then
mkdir $FAVORITE_THEMES_DIR
fi
# Load theme (random/favorite/specific)
load_theme
# Check for updates on initial load...
if [ "$DISABLE_AUTO_UPDATE" = "true" ]