From 87d3aa422806de1a964a4b63352b393343626142 Mon Sep 17 00:00:00 2001 From: deluxghost Date: Sat, 2 Sep 2017 18:32:20 +0800 Subject: [PATCH] Update themes plugin to support custom themes function lstheme won't cd to themes directory anymore. --- plugins/themes/themes.plugin.zsh | 32 ++++++++++++++++++-------------- 1 file changed, 18 insertions(+), 14 deletions(-) diff --git a/plugins/themes/themes.plugin.zsh b/plugins/themes/themes.plugin.zsh index 7519b025..d94bf4c4 100644 --- a/plugins/themes/themes.plugin.zsh +++ b/plugins/themes/themes.plugin.zsh @@ -1,24 +1,28 @@ 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..." + themes=($ZSH/themes/*.zsh-theme) + N=${#themes[@]} + ((N=(RANDOM%N)+1)) + RANDOM_THEME=${themes[$N]} + source "$RANDOM_THEME" + RANDOM_THEME_NAME=`echo "$RANDOM_THEME"|xargs -d '\n' -n 1 basename|sed 's/\(.*\)\..*/\1/'` + echo "[oh-my-zsh] Random theme '$RANDOM_THEME_NAME' loaded." else - if [ -f "$ZSH_CUSTOM/$1.zsh-theme" ] - then - source "$ZSH_CUSTOM/$1.zsh-theme" - else - source "$ZSH/themes/$1.zsh-theme" - fi + if [ -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 + echo "[oh-my-zsh] Theme '$1' not found." + fi fi } function lstheme { - cd $ZSH/themes - ls *zsh-theme | sed 's,\.zsh-theme$,,' + ls -1 $ZSH/themes/*.zsh-theme $ZSH_CUSTOM/themes/*.zsh-theme \ + | xargs -d '\n' -n 1 basename \ + | sed 's/\(.*\)\..*/\1/' \ + | uniq | sort | column }