diff --git a/lib/functions.zsh b/lib/functions.zsh index ce46f751d..a13386fb3 100644 --- a/lib/functions.zsh +++ b/lib/functions.zsh @@ -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 +} diff --git a/oh-my-zsh.sh b/oh-my-zsh.sh index 6ffb9a2d3..daef0d1fe 100644 --- a/oh-my-zsh.sh +++ b/oh-my-zsh.sh @@ -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" ]