mirror of
https://github.com/ohmyzsh/ohmyzsh.git
synced 2026-02-27 03:05:39 +01:00
Random theme functionality encapsulated in a theme.
The statements for selecting a random theme in oh-my-zsh.sh and the themes plugin are duplicate. Most people eventually eventually settle on a theme, making those lines in oh-my-zsh.sh superfluous. To address those, it may make sense to put the random theme functionality into a theme of its own (since themes are just zsh-script).
This commit is contained in:
parent
cea29ff7ce
commit
1ceb8eabc0
3 changed files with 21 additions and 29 deletions
23
oh-my-zsh.sh
23
oh-my-zsh.sh
|
|
@ -70,21 +70,12 @@ done
|
||||||
unset config_file
|
unset config_file
|
||||||
|
|
||||||
# Load the theme
|
# Load the theme
|
||||||
if [ "$ZSH_THEME" = "random" ]; then
|
if [ ! "$ZSH_THEME" = "" ]; then
|
||||||
themes=($ZSH/themes/*zsh-theme)
|
if [ -f "$ZSH_CUSTOM/$ZSH_THEME.zsh-theme" ]; then
|
||||||
N=${#themes[@]}
|
source "$ZSH_CUSTOM/$ZSH_THEME.zsh-theme"
|
||||||
((N=(RANDOM%N)+1))
|
elif [ -f "$ZSH_CUSTOM/themes/$ZSH_THEME.zsh-theme" ]; then
|
||||||
RANDOM_THEME=${themes[$N]}
|
source "$ZSH_CUSTOM/themes/$ZSH_THEME.zsh-theme"
|
||||||
source "$RANDOM_THEME"
|
else
|
||||||
echo "[oh-my-zsh] Random theme '$RANDOM_THEME' loaded..."
|
source "$ZSH/themes/$ZSH_THEME.zsh-theme"
|
||||||
else
|
|
||||||
if [ ! "$ZSH_THEME" = "" ]; then
|
|
||||||
if [ -f "$ZSH_CUSTOM/$ZSH_THEME.zsh-theme" ]; then
|
|
||||||
source "$ZSH_CUSTOM/$ZSH_THEME.zsh-theme"
|
|
||||||
elif [ -f "$ZSH_CUSTOM/themes/$ZSH_THEME.zsh-theme" ]; then
|
|
||||||
source "$ZSH_CUSTOM/themes/$ZSH_THEME.zsh-theme"
|
|
||||||
else
|
|
||||||
source "$ZSH/themes/$ZSH_THEME.zsh-theme"
|
|
||||||
fi
|
|
||||||
fi
|
fi
|
||||||
fi
|
fi
|
||||||
|
|
|
||||||
|
|
@ -1,19 +1,14 @@
|
||||||
function theme
|
function theme
|
||||||
{
|
{
|
||||||
if [ -z "$1" ] || [ "$1" = "random" ]; then
|
if [ -z "$1" ]; then
|
||||||
themes=($ZSH/themes/*zsh-theme)
|
1="random"
|
||||||
N=${#themes[@]}
|
fi
|
||||||
((N=(RANDOM%N)+1))
|
|
||||||
RANDOM_THEME=${themes[$N]}
|
if [ -f "$ZSH_CUSTOM/$1.zsh-theme" ]
|
||||||
source "$RANDOM_THEME"
|
then
|
||||||
echo "[oh-my-zsh] Random theme '$RANDOM_THEME' loaded..."
|
source "$ZSH_CUSTOM/$1.zsh-theme"
|
||||||
else
|
else
|
||||||
if [ -f "$ZSH_CUSTOM/$1.zsh-theme" ]
|
source "$ZSH/themes/$1.zsh-theme"
|
||||||
then
|
|
||||||
source "$ZSH_CUSTOM/$1.zsh-theme"
|
|
||||||
else
|
|
||||||
source "$ZSH/themes/$1.zsh-theme"
|
|
||||||
fi
|
|
||||||
fi
|
fi
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
6
themes/random.zsh-theme
Normal file
6
themes/random.zsh-theme
Normal file
|
|
@ -0,0 +1,6 @@
|
||||||
|
themes=($ZSH/themes/*zsh-theme)
|
||||||
|
N=${#themes[@]}
|
||||||
|
((N=(RANDOM%N)+1))
|
||||||
|
RANDOM_THEME=${themes[$N]}
|
||||||
|
source "$RANDOM_THEME"
|
||||||
|
echo "[oh-my-zsh] Random theme '$RANDOM_THEME' loaded..."
|
||||||
Loading…
Add table
Add a link
Reference in a new issue