themes can now be previewed via changetheme

This commit is contained in:
Joel Holdbrooks 2011-06-08 01:13:10 -07:00
commit c00e69b4eb

View file

@ -1,17 +1,22 @@
export ZSH_THEMES_PATH=$ZSH/themes
# Directly change a theme # Directly change a theme
function usetheme() { function usetheme() {
if [ $1 ] && theme_name=${1%.zsh-theme}; then if [ $1 ] && theme_name=${1%.zsh-theme}; then
printf "Changing theme to $1... " if [ $theme_name = $ZSH_THEME ]; then
print "Maintaining theme... "
if [ -f $ZSH_THEMES_PATH/$theme_name.zsh-theme ]; then # A work-around when used through changetheme
source $ZSH_THEMES_PATH/$theme_name.zsh-theme source "$ZSH/themes/$theme_name.zsh-theme"
export ZSH_THEME=$theme_name
echo "$fg_bold[green]Done"
else else
printf "$fg_bold[red]Error$reset_color: " printf "Changing theme to $1... "
echo "Could not find theme: '$theme_name.zsh-theme' in $ZSH_THEMES_PATH"
if [ -f "$ZSH/themes/$theme_name.zsh-theme" ]; then
source "$ZSH/themes/$theme_name.zsh-theme"
export ZSH_THEME=$theme_name
echo "$fg_bold[green]Done$reset_color"
else
printf "$fg_bold[red]Error$reset_color: "
echo "Could not find theme: '$theme_name.zsh-theme' in $ZSH_THEMES_PATH"
fi
fi fi
else else
@ -24,27 +29,45 @@ function changetheme() {
if [ $1 ]; then if [ $1 ]; then
usetheme "$1" usetheme "$1"
else else
theme_files=($ZSH_THEMES_PATH/*) theme_files=($ZSH/themes/*)
theme_names=(${${theme_files[@]##*/}[@]%.zsh-theme}) theme_names=(${${theme_files[@]##*/}[@]%.zsh-theme})
PS3="Enter your selection: " PS3="Enter your selection: "
SELECTION="" print "Themes available:"
select theme_name in ${theme_names[@]} Quit
echo "Themes available:"
select theme in ${theme_names[@]} Quit
do do
case $theme in case $theme_name in
Quit) Quit)
echo "Exiting... " echo "Exiting... "
exit;; exit;;
*) *)
SELECTION=$REPLY theme_selection=$REPLY
break printf "Would you like to preview this theme before applying? [yn]: "
;; read confirmation
case $confirmation in
y*)
source "${theme_files[$theme_selection]}"
PS3="$PROMPT"
echo "Apply theme? ";
select theme_confirmation in yes no
do
case $theme_confirmation in
yes)
theme="${theme_names[$theme_selection]}"
break;;
no)
theme="$ZSH_THEME.zsh-theme"
break;;
esac
done;
break;;
n*) break;;
esac
break;;
esac esac
done done
unset PS3
theme="${theme_names[$SELECTION]}"
usetheme $theme usetheme $theme
fi fi
} }