summaryrefslogtreecommitdiff
path: root/plugins/themes
diff options
context:
space:
mode:
Diffstat (limited to 'plugins/themes')
-rw-r--r--plugins/themes/README.md18
-rw-r--r--plugins/themes/_theme3
-rw-r--r--plugins/themes/themes.plugin.zsh41
3 files changed, 40 insertions, 22 deletions
diff --git a/plugins/themes/README.md b/plugins/themes/README.md
new file mode 100644
index 000000000..408e357e0
--- /dev/null
+++ b/plugins/themes/README.md
@@ -0,0 +1,18 @@
+# Themes Plugin
+
+This plugin allows you to change ZSH theme on the go.
+
+To use it, add `themes` to the plugins array in your zshrc file:
+
+```
+plugins=(... themes)
+```
+
+## Usage
+
+`theme <theme_name>` - Changes the ZSH theme to specified theme.
+
+`theme ` - Changes the ZSH theme to some random theme.
+
+`lstheme ` - Lists installed ZSH themes.
+
diff --git a/plugins/themes/_theme b/plugins/themes/_theme
deleted file mode 100644
index 8214ddb0d..000000000
--- a/plugins/themes/_theme
+++ /dev/null
@@ -1,3 +0,0 @@
-#compdef theme
-
-_arguments "1: :($(lstheme | tr "\n" " "))"
diff --git a/plugins/themes/themes.plugin.zsh b/plugins/themes/themes.plugin.zsh
index 7519b0253..1fbde5b64 100644
--- a/plugins/themes/themes.plugin.zsh
+++ b/plugins/themes/themes.plugin.zsh
@@ -1,24 +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/$1.zsh-theme" ]
- then
- source "$ZSH_CUSTOM/$1.zsh-theme"
- else
- source "$ZSH/themes/$1.zsh-theme"
- fi
+ echo "$0: Theme '$1' not found"
+ return 1
fi
}
-function lstheme
-{
- cd $ZSH/themes
- ls *zsh-theme | sed 's,\.zsh-theme$,,'
+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 "$ZSH_CUSTOM"/*.zsh-theme(N:t:r) {"$ZSH_CUSTOM","$ZSH"}/themes/*.zsh-theme(N:t:r)
}