theme-admin: Add support for pre-selecting random themes in a basic way.

This commit is contained in:
Javier Domingo Cansino 2014-06-23 18:19:21 +02:00
commit 20ab45218c
3 changed files with 25 additions and 2 deletions

View file

@ -69,10 +69,19 @@ unset config_file
# Load the theme
if [ "$ZSH_THEME" = "random" ]; then
themes=($ZSH/themes/*zsh-theme)
if [ -f "$THEMES_FILE" ]; then
echo "[oh-my-zsh] Found custom theme file $THEMES_FILE"
themes=($(<$THEMES_FILE))
else
themes=($ZSH/themes/*zsh-theme)
fi
N=${#themes[@]}
((N=(RANDOM%N)+1))
RANDOM_THEME=${themes[$N]}
if [ -f "$THEMES_FILE" ]; then
RANDOM_THEME="$ZSH/themes/$RANDOM_THEME"
alias oh-my-zsh-theme-remove="echo 'Removing theme ${themes[$N]}' ; sed -i.old '/$(basename ${themes[$N]})/d' $THEMES_FILE"
fi
source "$RANDOM_THEME"
echo "[oh-my-zsh] Random theme '$RANDOM_THEME' loaded..."
else

View file

@ -1,10 +1,19 @@
function theme
{
if [ -z "$1" ] || [ "$1" = "random" ]; then
themes=($ZSH/themes/*zsh-theme)
if [ -f "$THEMES_FILE" ]; then
echo "[oh-my-zsh] Found custom theme file $THEMES_FILE"
themes=($(<$THEMES_FILE))
alias oh-my-zsh-theme-remove='echo "Removing theme ${themes[$N]}" ; sed -i.old "/$(basename ${themes[$N]})/d" $THEMES_FILE'
else
themes=($ZSH/themes/*zsh-theme)
fi
N=${#themes[@]}
((N=(RANDOM%N)+1))
RANDOM_THEME=${themes[$N]}
if [ -f "$THEMES_FILE" ]; then
RANDOM_THEME="$ZSH/themes/$RANDOM_THEME"
fi
source "$RANDOM_THEME"
echo "[oh-my-zsh] Random theme '$RANDOM_THEME' loaded..."
else

View file

@ -5,6 +5,11 @@ export ZSH=$HOME/.oh-my-zsh
# Look in ~/.oh-my-zsh/themes/
# Optionally, if you set this to "random", it'll load a random theme each
# time that oh-my-zsh is loaded.
# You may specify THEMES_FILE in case you want an specific set of themes
# with it, oh-my-zsh-theme-remove will ease erasing the current theme
# from the THEMES_FILE.
# ls $ZSH/themes/*.zsh-theme | xargs -n1 basename > $THEMES_FILE
# THEMES_FILE="$HOME/.omz-themes"
ZSH_THEME="robbyrussell"
# Example aliases