diff options
author | Marc Cornellà <marc.cornella@live.com> | 2020-02-19 20:26:45 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2020-02-19 20:26:45 +0100 |
commit | bc9fe7423f5d8c639b208ebb9a7dbfce078bfd9b (patch) | |
tree | 66b959555d5227f0f9889c5347eb513a266bce22 /plugins/themes/themes.plugin.zsh | |
parent | d76258ff554ea58d9865b9864f5fff1dd8d2e4bb (diff) | |
parent | 3d4890dcc07478e7129de1e79afedafd3f08ffbc (diff) | |
download | zsh-bc9fe7423f5d8c639b208ebb9a7dbfce078bfd9b.tar.gz zsh-bc9fe7423f5d8c639b208ebb9a7dbfce078bfd9b.tar.bz2 zsh-bc9fe7423f5d8c639b208ebb9a7dbfce078bfd9b.zip |
Merge pull request #8651 from mcornella/random-theme-refactor
Add random theme and consolidate logic from init and themes plugin
Diffstat (limited to 'plugins/themes/themes.plugin.zsh')
-rw-r--r-- | plugins/themes/themes.plugin.zsh | 37 |
1 files changed, 19 insertions, 18 deletions
diff --git a/plugins/themes/themes.plugin.zsh b/plugins/themes/themes.plugin.zsh index 2cd0ee327..1fbde5b64 100644 --- a/plugins/themes/themes.plugin.zsh +++ b/plugins/themes/themes.plugin.zsh @@ -1,26 +1,27 @@ -function theme -{ - if [ -z "$1" ] || [ "$1" = "random" ]; then - 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..." +function theme { + : ${1:=random} # Use random theme if none provided + + if [[ -f "$ZSH_CUSTOM/$1.zsh-theme" ]]; then + source "$ZSH_CUSTOM/$1.zsh-theme" + elif [[ -f "$ZSH_CUSTOM/themes/$1.zsh-theme" ]]; then + source "$ZSH_CUSTOM/themes/$1.zsh-theme" + elif [[ -f "$ZSH/themes/$1.zsh-theme" ]]; then + source "$ZSH/themes/$1.zsh-theme" else - if [ -f "$ZSH_CUSTOM/themes/$1.zsh-theme" ] - then - source "$ZSH_CUSTOM/themes/$1.zsh-theme" - else - source "$ZSH/themes/$1.zsh-theme" - fi + echo "$0: Theme '$1' not found" + return 1 fi } -function lstheme -{ +function _theme { + _arguments "1: :($(lstheme))" +} + +compdef _theme theme + +function lstheme { # Resources: # http://zsh.sourceforge.net/Doc/Release/Expansion.html#Modifiers # http://zsh.sourceforge.net/Doc/Release/Expansion.html#Glob-Qualifiers - print -l {$ZSH,$ZSH_CUSTOM}/themes/*.zsh-theme(N:t:r) + print "$ZSH_CUSTOM"/*.zsh-theme(N:t:r) {"$ZSH_CUSTOM","$ZSH"}/themes/*.zsh-theme(N:t:r) } |