theme_chooser.sh
3628 bytes
1#!/usr/bin/env 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
10THEMES_DIR="$ZSH/themes"
11FAVLIST="${HOME}/.zsh_favlist"
12source $ZSH/oh-my-zsh.sh
13
14function 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
22function 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
32function banner() {
33 echo
34 echo "[0;1;35;95m╺━[0;1;31;91m┓┏[0;1;33;93m━┓[0;1;32;92m╻[0m [0;1;36;96m╻[0m [0;1;35;95m╺┳[0;1;31;91m╸╻[0m [0;1;33;93m╻[0;1;32;92m┏━[0;1;36;96m╸┏[0;1;34;94m┳┓[0;1;35;95m┏━[0;1;31;91m╸[0m [0;1;32;92m┏━[0;1;36;96m╸╻[0m [0;1;34;94m╻[0;1;35;95m┏━[0;1;31;91m┓┏[0;1;33;93m━┓[0;1;32;92m┏━[0;1;36;96m┓┏[0;1;34;94m━╸[0;1;35;95m┏━[0;1;31;91m┓[0m"
35 echo "[0;1;31;91m┏━[0;1;33;93m┛┗[0;1;32;92m━┓[0;1;36;96m┣━[0;1;34;94m┫[0m [0;1;31;91m┃[0m [0;1;33;93m┣[0;1;32;92m━┫[0;1;36;96m┣╸[0m [0;1;34;94m┃[0;1;35;95m┃┃[0;1;31;91m┣╸[0m [0;1;36;96m┃[0m [0;1;34;94m┣[0;1;35;95m━┫[0;1;31;91m┃[0m [0;1;33;93m┃┃[0m [0;1;32;92m┃[0;1;36;96m┗━[0;1;34;94m┓┣[0;1;35;95m╸[0m [0;1;31;91m┣┳[0;1;33;93m┛[0m"
36 echo "[0;1;33;93m┗━[0;1;32;92m╸┗[0;1;36;96m━┛[0;1;34;94m╹[0m [0;1;35;95m╹[0m [0;1;33;93m╹[0m [0;1;32;92m╹[0m [0;1;36;96m╹[0;1;34;94m┗━[0;1;35;95m╸╹[0m [0;1;31;91m╹[0;1;33;93m┗━[0;1;32;92m╸[0m [0;1;34;94m┗━[0;1;35;95m╸╹[0m [0;1;31;91m╹[0;1;33;93m┗━[0;1;32;92m┛┗[0;1;36;96m━┛[0;1;34;94m┗━[0;1;35;95m┛┗[0;1;31;91m━╸[0;1;33;93m╹┗[0;1;32;92m╸[0m"
37 echo
38}
39
40function 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
50function 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
57function 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
67function 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
80while getopts ":lhs" Option
81do
82 case $Option in
83 l ) list_themes ;;
84 s ) theme_chooser 0 ;;
85 h ) usage ;;
86 * ) usage ;; # Default.
87 esac
88done
89
90if [[ -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
98fi