From 45dc772c7c4147155960dec3a7ee4554b7ba0fa6 Mon Sep 17 00:00:00 2001 From: Luke Lee Date: Fri, 3 Jun 2011 19:03:07 -0500 Subject: [PATCH] Add ability to switch between 'random' themes and 'favorite' themes - Refactored code for getting a random theme into a function - Setting your theme to 'favorites' will now pick a random theme from your favorites and setting theme to 'random' will pick a random theme from ALL available themes --- lib/functions.zsh | 10 ++++++++++ oh-my-zsh.sh | 21 +++++++-------------- 2 files changed, 17 insertions(+), 14 deletions(-) diff --git a/lib/functions.zsh b/lib/functions.zsh index d2f68cb88..279921bd4 100644 --- a/lib/functions.zsh +++ b/lib/functions.zsh @@ -78,3 +78,13 @@ function unlike_theme() { echo "$theme_name isn't a favorite" fi } + +function load_random_theme() { + themes=($*) + N=${#themes[@]} + ((N=(RANDOM%N)+1)) + RANDOM_THEME=${themes[$N]} + source "$RANDOM_THEME" + echo "[oh-my-zsh] Random theme '$RANDOM_THEME' loaded..." + export RANDOM_THEME +} diff --git a/oh-my-zsh.sh b/oh-my-zsh.sh index b4f70e922..5ea7fc089 100644 --- a/oh-my-zsh.sh +++ b/oh-my-zsh.sh @@ -34,29 +34,22 @@ done for config_file ($ZSH/custom/*.zsh) source $config_file export FAVORITE_THEMES_DIR="$ZSH/themes/favorites/" - -# Load the theme -# Check for updates on initial load... -if [ "$ZSH_THEME" = "random" ] -then # 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 $ZSH/themes/*zsh-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 - themes=($FAVORITE_THEMES_DIR/*zsh-theme) + load_random_theme $FAVORITE_THEMES_DIR/*zsh-theme else - themes=($ZSH/themes/*zsh-theme) + load_random_theme $ZSH/themes/*zsh-theme fi - - N=${#themes[@]} - ((N=(RANDOM%N)+1)) - RANDOM_THEME=${themes[$N]} - source "$RANDOM_THEME" - echo "[oh-my-zsh] Random theme '$RANDOM_THEME' loaded..." - export RANDOM_THEME else source "$ZSH/themes/$ZSH_THEME.zsh-theme" fi