]> src.twobees.de Git - dotfiles.git/blob - stow/oh-my-zsh/.oh-my-zsh/tools/theme_chooser.sh
initial
[dotfiles.git] / stow / oh-my-zsh / .oh-my-zsh / tools / theme_chooser.sh
1 #!/bin/zsh
2
3 # Zsh Theme Chooser by fox (fox91 at anche dot no)
4 # This program is free software. It comes without any warranty, to
5 # the extent permitted by applicable law. You can redistribute it
6 # and/or modify it under the terms of the Do What The Fuck You Want
7 # To Public License, Version 2, as published by Sam Hocevar. See
8 # http://www.wtfpl.net/txt/copying/ for more details.
9
10 THEMES_DIR="$ZSH/themes"
11 FAVLIST="${HOME}/.zsh_favlist"
12 source $ZSH/oh-my-zsh.sh
13
14 function noyes() {
15     read "a?$1 [y/N] "
16     if [[ $a == "N" || $a == "n" || $a = "" ]]; then
17         return 0
18     fi
19     return 1
20 }
21
22 function theme_preview() {
23     THEME=$1
24     THEME_NAME=`echo $THEME | sed s/\.zsh-theme$//`
25     print "$fg[blue]${(l.((${COLUMNS}-${#THEME_NAME}-5))..─.)}$reset_color $THEME_NAME $fg[blue]───$reset_color"
26     source "$THEMES_DIR/$THEME"
27     cols=$(tput cols)
28     (exit 1)
29     print -P "$PROMPT                                                                                      $RPROMPT"
30 }
31
32 function banner() {
33     echo
34     echo "\e[0;1;35;95m╺━\e[0;1;31;91m┓┏\e[0;1;33;93m━┓\e[0;1;32;92m╻\e[0m \e[0;1;36;96m╻\e[0m   \e[0;1;35;95m╺┳\e[0;1;31;91m╸╻\e[0m \e[0;1;33;93m╻\e[0;1;32;92m┏━\e[0;1;36;96m╸┏\e[0;1;34;94m┳┓\e[0;1;35;95m┏━\e[0;1;31;91m╸\e[0m   \e[0;1;32;92m┏━\e[0;1;36;96m╸╻\e[0m \e[0;1;34;94m╻\e[0;1;35;95m┏━\e[0;1;31;91m┓┏\e[0;1;33;93m━┓\e[0;1;32;92m┏━\e[0;1;36;96m┓┏\e[0;1;34;94m━╸\e[0;1;35;95m┏━\e[0;1;31;91m┓\e[0m"
35     echo "\e[0;1;31;91m┏━\e[0;1;33;93m┛┗\e[0;1;32;92m━┓\e[0;1;36;96m┣━\e[0;1;34;94m┫\e[0m    \e[0;1;31;91m┃\e[0m \e[0;1;33;93m┣\e[0;1;32;92m━┫\e[0;1;36;96m┣╸\e[0m \e[0;1;34;94m┃\e[0;1;35;95m┃┃\e[0;1;31;91m┣╸\e[0m    \e[0;1;36;96m┃\e[0m  \e[0;1;34;94m┣\e[0;1;35;95m━┫\e[0;1;31;91m┃\e[0m \e[0;1;33;93m┃┃\e[0m \e[0;1;32;92m┃\e[0;1;36;96m┗━\e[0;1;34;94m┓┣\e[0;1;35;95m╸\e[0m \e[0;1;31;91m┣┳\e[0;1;33;93m┛\e[0m"
36     echo "\e[0;1;33;93m┗━\e[0;1;32;92m╸┗\e[0;1;36;96m━┛\e[0;1;34;94m╹\e[0m \e[0;1;35;95m╹\e[0m    \e[0;1;33;93m╹\e[0m \e[0;1;32;92m╹\e[0m \e[0;1;36;96m╹\e[0;1;34;94m┗━\e[0;1;35;95m╸╹\e[0m \e[0;1;31;91m╹\e[0;1;33;93m┗━\e[0;1;32;92m╸\e[0m   \e[0;1;34;94m┗━\e[0;1;35;95m╸╹\e[0m \e[0;1;31;91m╹\e[0;1;33;93m┗━\e[0;1;32;92m┛┗\e[0;1;36;96m━┛\e[0;1;34;94m┗━\e[0;1;35;95m┛┗\e[0;1;31;91m━╸\e[0;1;33;93m╹┗\e[0;1;32;92m╸\e[0m"
37     echo
38 }
39
40 function usage() {
41     echo "Usage: $0 [options] [theme]"
42     echo
43     echo "Options"
44     echo "  -l   List available themes"
45     echo "  -s   Show all themes"
46     echo "  -h   Get this help message"
47     exit 1
48 }
49
50 function list_themes() {
51     for THEME in $(ls $THEMES_DIR); do
52         THEME_NAME=`echo $THEME | sed s/\.zsh-theme$//`
53         echo $THEME_NAME
54     done
55 }
56
57 function insert_favlist() {
58     if grep -q "$THEME_NAME" $FAVLIST 2> /dev/null ; then
59         echo "Already in favlist"
60     else
61         echo $THEME_NAME >> $FAVLIST
62         echo "Saved to favlist"
63     fi
64
65 }
66
67 function theme_chooser() {
68     for THEME in $(ls $THEMES_DIR); do
69         echo
70         theme_preview $THEME
71         echo
72         if [[ -z $1 ]]; then
73             noyes "Do you want to add it to your favourite list ($FAVLIST)?" || \
74                   insert_favlist $THEME_NAME
75             echo
76         fi
77     done
78 }
79
80 while getopts ":lhs" Option
81 do
82   case $Option in
83     l ) list_themes ;;
84     s ) theme_chooser 0 ;;
85     h ) usage ;;
86     * ) usage ;; # Default.
87   esac
88 done
89
90 if [[ -z $Option ]]; then
91     if [[ -z $1 ]]; then
92         banner
93         echo
94         theme_chooser
95     else
96         theme_preview $1".zsh-theme"
97     fi
98 fi