1
0
Fork 0
mirror of https://github.com/ohmyzsh/ohmyzsh.git synced 2024-11-14 01:40:09 +00:00
ohmyzsh/plugins/themes/themes.plugin.zsh
Marc Cornellà 2a3a940a45 themes: change lstheme function to themes in $ZSH_CUSTOM in any level
Also sort and remove duplicates, and pipe to fmt to improve output format.

Fixes #8755
2020-03-23 22:51:48 +01:00

35 lines
1.2 KiB
Bash

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
}