]> src.twobees.de Git - dotfiles.git/blob - stow/oh-my-zsh/.oh-my-zsh/plugins/themes/themes.plugin.zsh
...
[dotfiles.git] / stow / oh-my-zsh / .oh-my-zsh / plugins / themes / themes.plugin.zsh
1 function theme {
2     : ${1:=random} # Use random theme if none provided
3
4     if [[ -f "$ZSH_CUSTOM/$1.zsh-theme" ]]; then
5         source "$ZSH_CUSTOM/$1.zsh-theme"
6     elif [[ -f "$ZSH_CUSTOM/themes/$1.zsh-theme" ]]; then
7         source "$ZSH_CUSTOM/themes/$1.zsh-theme"
8     elif [[ -f "$ZSH/themes/$1.zsh-theme" ]]; then
9         source "$ZSH/themes/$1.zsh-theme"
10     else
11         echo "$0: Theme '$1' not found"
12         return 1
13     fi
14 }
15
16 function _theme {
17     _arguments "1: :($(lstheme))"
18 }
19
20 compdef _theme theme
21
22 function lstheme {
23     # Resources:
24     # http://zsh.sourceforge.net/Doc/Release/Expansion.html#Modifiers
25     # http://zsh.sourceforge.net/Doc/Release/Expansion.html#Glob-Qualifiers
26     {
27         # Show themes inside $ZSH_CUSTOM (in any subfolder)
28         # Strip $ZSH_CUSTOM/themes/ and $ZSH_CUSTOM/ from the name, so that it matches
29         # the value that should be written in $ZSH_THEME to load the theme.
30         print -l "$ZSH_CUSTOM"/**/*.zsh-theme(.N:r:gs:"$ZSH_CUSTOM"/themes/:::gs:"$ZSH_CUSTOM"/:::)
31
32         # Show themes inside $ZSH, stripping the head of the path.
33         print -l "$ZSH"/themes/*.zsh-theme(.N:t:r)
34     } | sort -u | fmt -w $COLUMNS
35 }