summaryrefslogtreecommitdiff
path: root/oh-my-zsh/plugins/themes
diff options
context:
space:
mode:
authorAditya <bluenerd@protonmail.com>2023-02-27 20:04:56 +0530
committerAditya <bluenerd@protonmail.com>2023-02-27 20:04:56 +0530
commitedc449275b6c04445f58b108ca0937a87c1e8430 (patch)
tree9fd484d58145b616f29a78857cc0b1c8b1c18f05 /oh-my-zsh/plugins/themes
parent6f5424ca96c4221ef433f545642669e9c104d0ed (diff)
add zsh
Diffstat (limited to 'oh-my-zsh/plugins/themes')
-rw-r--r--oh-my-zsh/plugins/themes/README.md18
-rw-r--r--oh-my-zsh/plugins/themes/themes.plugin.zsh35
2 files changed, 53 insertions, 0 deletions
diff --git a/oh-my-zsh/plugins/themes/README.md b/oh-my-zsh/plugins/themes/README.md
new file mode 100644
index 0000000..408e357
--- /dev/null
+++ b/oh-my-zsh/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/oh-my-zsh/plugins/themes/themes.plugin.zsh b/oh-my-zsh/plugins/themes/themes.plugin.zsh
new file mode 100644
index 0000000..6508562
--- /dev/null
+++ b/oh-my-zsh/plugins/themes/themes.plugin.zsh
@@ -0,0 +1,35 @@
+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
+ echo "$0: Theme '$1' not found"
+ return 1
+ fi
+}
+
+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
+ {
+ # Show themes inside $ZSH_CUSTOM (in any subfolder)
+ # Strip $ZSH_CUSTOM/themes/ and $ZSH_CUSTOM/ from the name, so that it matches
+ # the value that should be written in $ZSH_THEME to load the theme.
+ print -l "$ZSH_CUSTOM"/**/*.zsh-theme(.N:r:gs:"$ZSH_CUSTOM"/themes/:::gs:"$ZSH_CUSTOM"/:::)
+
+ # Show themes inside $ZSH, stripping the head of the path.
+ print -l "$ZSH"/themes/*.zsh-theme(.N:t:r)
+ } | sort -u | fmt -w $COLUMNS
+}