From 531c41cdfee9e3bbba16d0bf19ca973ad4bb4af5 Mon Sep 17 00:00:00 2001 From: LE Manh Cuong Date: Tue, 1 Dec 2015 11:50:55 +0700 Subject: [PATCH 1/2] Allow loading themes from predefined list --- oh-my-zsh.sh | 6 +++++- templates/zshrc.zsh-template | 6 ++++++ 2 files changed, 11 insertions(+), 1 deletion(-) diff --git a/oh-my-zsh.sh b/oh-my-zsh.sh index 6cc5ac63..0324543d 100644 --- a/oh-my-zsh.sh +++ b/oh-my-zsh.sh @@ -94,7 +94,11 @@ unset config_file # Load the theme if [ "$ZSH_THEME" = "random" ]; then - themes=($ZSH/themes/*zsh-theme) + if [ "${(t)ZSH_THEME_RANDOM_CANDICATES}" = "array" ] && [ "${#ZSH_THEME_RANDOM_CANDICATES[@]}" -gt 0 ]; then + themes=($ZSH/themes/${^ZSH_THEME_RANDOM_CANDICATES}.zsh-theme) + else + themes=($ZSH/themes/*zsh-theme) + fi N=${#themes[@]} ((N=(RANDOM%N)+1)) RANDOM_THEME=${themes[$N]} diff --git a/templates/zshrc.zsh-template b/templates/zshrc.zsh-template index 44e8b0d1..baedf067 100644 --- a/templates/zshrc.zsh-template +++ b/templates/zshrc.zsh-template @@ -7,6 +7,12 @@ export ZSH=$HOME/.oh-my-zsh # time that oh-my-zsh is loaded. ZSH_THEME="robbyrussell" +# Set list of themes to load +# Setting this variable when ZSH_THEME=random +# cause zsh load theme from this variable instead of +# looking in ~/.oh-my-zsh/themes/ +# ZSH_THEME_RANDOM_CANDICATES=() + # Uncomment the following line to use case-sensitive completion. # CASE_SENSITIVE="true" From 5e77e00ad522a5d6a84067d22015b85b0080a19f Mon Sep 17 00:00:00 2001 From: LE Manh Cuong Date: Tue, 1 Dec 2015 12:03:00 +0700 Subject: [PATCH 2/2] Some improvements - Adding documentation - Note the effect empty array - Fix spelling - Using new test `[[...]]` --- README.markdown | 8 ++++++++ oh-my-zsh.sh | 6 +++--- templates/zshrc.zsh-template | 3 ++- 3 files changed, 13 insertions(+), 4 deletions(-) diff --git a/README.markdown b/README.markdown index 9d7210f7..0d3144dd 100644 --- a/README.markdown +++ b/README.markdown @@ -88,6 +88,14 @@ If you're feeling feisty, you can let the computer select one randomly for you e ZSH_THEME="random" # (...please let it be pie... please be some pie..) ``` +And if you want to pick random theme from a list of your favorite themes: + +```shell +ZSH_THEM_RANDOM_CANDIDATES=( + "robbyrussell" + "agnoster" +) +``` ## Advanced Topics diff --git a/oh-my-zsh.sh b/oh-my-zsh.sh index 0324543d..4517a2ba 100644 --- a/oh-my-zsh.sh +++ b/oh-my-zsh.sh @@ -93,9 +93,9 @@ done unset config_file # Load the theme -if [ "$ZSH_THEME" = "random" ]; then - if [ "${(t)ZSH_THEME_RANDOM_CANDICATES}" = "array" ] && [ "${#ZSH_THEME_RANDOM_CANDICATES[@]}" -gt 0 ]; then - themes=($ZSH/themes/${^ZSH_THEME_RANDOM_CANDICATES}.zsh-theme) +if [[ "$ZSH_THEME" == "random" ]]; 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 diff --git a/templates/zshrc.zsh-template b/templates/zshrc.zsh-template index baedf067..2f39308a 100644 --- a/templates/zshrc.zsh-template +++ b/templates/zshrc.zsh-template @@ -11,7 +11,8 @@ ZSH_THEME="robbyrussell" # Setting this variable when ZSH_THEME=random # cause zsh load theme from this variable instead of # looking in ~/.oh-my-zsh/themes/ -# ZSH_THEME_RANDOM_CANDICATES=() +# An empty array have no effect +# ZSH_THEME_RANDOM_CANDIDATES=( "robbyrussell" "agnoster" ) # Uncomment the following line to use case-sensitive completion. # CASE_SENSITIVE="true"