Default themes argument

- This allows the function to be used from the shell as a shortcut to sourcing
  ~/.zshrc to load a new random theme
- Refactor out list of all available themes
This commit is contained in:
Luke Lee 2011-06-03 19:04:15 -05:00
commit 899d9d5ab3
2 changed files with 9 additions and 3 deletions

View file

@ -86,7 +86,13 @@ function unlike_theme() {
} }
function load_random_theme() { function load_random_theme() {
# Default theme selection
if [ $# -eq 0 ]; then
themes=($ZSH/themes/*zsh-theme)
else
themes=($*) themes=($*)
fi
N=${#themes[@]} N=${#themes[@]}
((N=(RANDOM%N)+1)) ((N=(RANDOM%N)+1))
RANDOM_THEME=${themes[$N]} RANDOM_THEME=${themes[$N]}

View file

@ -42,13 +42,13 @@ export FAVORITE_THEMES_DIR="$ZSH/themes/favorites/"
# Load the theme # Load the theme
# Check for updates on initial load... # Check for updates on initial load...
if [ "$ZSH_THEME" = "random" ]; then if [ "$ZSH_THEME" = "random" ]; then
load_random_theme $ZSH/themes/*zsh-theme load_random_theme
elif [ "$ZSH_THEME" = "favorites" ]; then elif [ "$ZSH_THEME" = "favorites" ]; then
# Only randomize with liked themes if there are any # Only randomize with liked themes if there are any
if [ `ls $FAVORITE_THEMES_DIR | wc -w` -gt 0 ]; then if [ `ls $FAVORITE_THEMES_DIR | wc -w` -gt 0 ]; then
load_random_theme $FAVORITE_THEMES_DIR/*zsh-theme load_random_theme $FAVORITE_THEMES_DIR/*zsh-theme
else else
load_random_theme $ZSH/themes/*zsh-theme load_random_theme
fi fi
else else
source "$ZSH/themes/$ZSH_THEME.zsh-theme" source "$ZSH/themes/$ZSH_THEME.zsh-theme"