浏览代码

Polish themes plugin and error out if theme not found

Marc Cornellà 4 年之前
父节点
当前提交
f4b4a446ac
共有 2 个文件被更改,包括 16 次插入16 次删除
  1. 0 3
      plugins/themes/_theme
  2. 16 13
      plugins/themes/themes.plugin.zsh

+ 0 - 3
plugins/themes/_theme

@@ -1,3 +0,0 @@
-#compdef theme
-
-_arguments "1: :($(lstheme | tr "\n" " "))"

+ 16 - 13
plugins/themes/themes.plugin.zsh

@@ -1,24 +1,27 @@
-function theme
-{
-    if [ -z "$1" ]; then
-        1="random"
-    fi
+function theme {
+    : ${1:=random} # Use random theme if none provided
 
-    if [ -f "$ZSH_CUSTOM/$1.zsh-theme" ]
-    then
+    if [[ -f "$ZSH_CUSTOM/$1.zsh-theme" ]]; then
         source "$ZSH_CUSTOM/$1.zsh-theme"
-    elif [ -f "$ZSH_CUSTOM/themes/$1.zsh-theme" ]
-    then
+    elif [[ -f "$ZSH_CUSTOM/themes/$1.zsh-theme" ]]; then
         source "$ZSH_CUSTOM/themes/$1.zsh-theme"
-    else
+    elif [[ -f "$ZSH/themes/$1.zsh-theme" ]]; then
         source "$ZSH/themes/$1.zsh-theme"
+    else
+        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)
 }