mirror of
https://github.com/ohmyzsh/ohmyzsh.git
synced 2024-11-29 03:03:59 +01:00
Move random theme functionality into "random" theme
The statements for selecting a random theme in oh-my-zsh.sh and the themes plugin are duplicate. Most people eventually settle on a theme, making those lines in oh-my-zsh.sh superfluous. To address those, it may makes sense to put the random theme functionality into a theme of its own (since themes are just zsh scripts.
This commit is contained in:
parent
d76258ff55
commit
6adad5c300
15
oh-my-zsh.sh
15
oh-my-zsh.sh
@ -97,19 +97,7 @@ done
|
|||||||
unset config_file
|
unset config_file
|
||||||
|
|
||||||
# Load the theme
|
# Load the theme
|
||||||
if [[ "$ZSH_THEME" == "random" ]]; then
|
if [ ! "$ZSH_THEME" = "" ]; then
|
||||||
if [[ "${(t)ZSH_THEME_RANDOM_CANDIDATES}" = "array" ]] && [[ "${#ZSH_THEME_RANDOM_CANDIDATES[@]}" -gt 0 ]]; then
|
|
||||||
themes=($ZSH/themes/${^ZSH_THEME_RANDOM_CANDIDATES}.zsh-theme)
|
|
||||||
else
|
|
||||||
themes=($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..."
|
|
||||||
else
|
|
||||||
if [ ! "$ZSH_THEME" = "" ]; then
|
|
||||||
if [ -f "$ZSH_CUSTOM/$ZSH_THEME.zsh-theme" ]; then
|
if [ -f "$ZSH_CUSTOM/$ZSH_THEME.zsh-theme" ]; then
|
||||||
source "$ZSH_CUSTOM/$ZSH_THEME.zsh-theme"
|
source "$ZSH_CUSTOM/$ZSH_THEME.zsh-theme"
|
||||||
elif [ -f "$ZSH_CUSTOM/themes/$ZSH_THEME.zsh-theme" ]; then
|
elif [ -f "$ZSH_CUSTOM/themes/$ZSH_THEME.zsh-theme" ]; then
|
||||||
@ -117,5 +105,4 @@ else
|
|||||||
else
|
else
|
||||||
source "$ZSH/themes/$ZSH_THEME.zsh-theme"
|
source "$ZSH/themes/$ZSH_THEME.zsh-theme"
|
||||||
fi
|
fi
|
||||||
fi
|
|
||||||
fi
|
fi
|
||||||
|
@ -1,20 +1,18 @@
|
|||||||
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
|
elif [ -f "$ZSH_CUSTOM/themes/$1.zsh-theme" ]
|
||||||
if [ -f "$ZSH_CUSTOM/themes/$1.zsh-theme" ]
|
|
||||||
then
|
then
|
||||||
source "$ZSH_CUSTOM/themes/$1.zsh-theme"
|
source "$ZSH_CUSTOM/themes/$1.zsh-theme"
|
||||||
else
|
else
|
||||||
source "$ZSH/themes/$1.zsh-theme"
|
source "$ZSH/themes/$1.zsh-theme"
|
||||||
fi
|
fi
|
||||||
fi
|
|
||||||
}
|
}
|
||||||
|
|
||||||
function lstheme
|
function lstheme
|
||||||
|
10
themes/random.zsh-theme
Normal file
10
themes/random.zsh-theme
Normal file
@ -0,0 +1,10 @@
|
|||||||
|
if [[ "${(t)ZSH_THEME_RANDOM_CANDIDATES}" = "array" ]] && [[ "${#ZSH_THEME_RANDOM_CANDIDATES[@]}" -gt 0 ]]; then
|
||||||
|
themes=($ZSH/themes/${^ZSH_THEME_RANDOM_CANDIDATES}.zsh-theme)
|
||||||
|
else
|
||||||
|
themes=($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..."
|
Loading…
Reference in New Issue
Block a user