theme_chooser.sh 3.52 KB
Newer Older
1
#!/bin/zsh
fox's avatar
fox committed
2
3
4
5
6
7

# Zsh Theme Chooser by fox (fox91 at anche dot no)
# This program is free software. It comes without any warranty, to
# the extent permitted by applicable law. You can redistribute it
# and/or modify it under the terms of the Do What The Fuck You Want
# To Public License, Version 2, as published by Sam Hocevar. See
Janosch Schwalm's avatar
Janosch Schwalm committed
8
# http://www.wtfpl.net/txt/copying/ for more details.
fox's avatar
fox committed
9
10

THEMES_DIR="$ZSH/themes"
fox's avatar
fox committed
11
FAVLIST="${HOME}/.zsh_favlist"
12
source $ZSH/oh-my-zsh.sh
fox's avatar
fox committed
13
14

function noyes() {
15
    read "a?$1 [y/N] "
fox's avatar
fox committed
16
17
18
19
20
21
22
23
    if [[ $a == "N" || $a == "n" || $a = "" ]]; then
        return 0
    fi
    return 1
}

function theme_preview() {
    THEME=$1
24
25
26
    THEME_NAME=`echo $THEME | sed s/\.zsh-theme$//`
    print "$fg[blue]${(l.((${COLUMNS}-${#THEME_NAME}-5))..─.)}$reset_color $THEME_NAME $fg[blue]───$reset_color"
    source "$THEMES_DIR/$THEME"
27
28
    cols=$(tput cols)
    print -P "$PROMPT                                                                                      $RPROMPT"
29
}
fox's avatar
fox committed
30

31
function banner() {
fox's avatar
fox committed
32
    echo
33
34
35
    echo "╺━┓┏━┓╻ ╻   ╺┳╸╻ ╻┏━╸┏┳┓┏━╸   ┏━╸╻ ╻┏━┓┏━┓┏━┓┏━╸┏━┓"
    echo "┏━┛┗━┓┣━┫    ┃ ┣━┫┣╸ ┃┃┃┣╸    ┃  ┣━┫┃ ┃┃ ┃┗━┓┣╸ ┣┳┛"
    echo "┗━╸┗━┛╹ ╹    ╹ ╹ ╹┗━╸╹ ╹┗━╸   ┗━╸╹ ╹┗━┛┗━┛┗━┛┗━╸╹┗╸"
fox's avatar
fox committed
36
37
38
    echo
}

39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
function usage() {
    echo "Usage: $0 [options] [theme]"
    echo
    echo "Options"
    echo "  -l   List available themes"
    echo "  -s   Show all themes"
    echo "  -h   Get this help message"
    exit 1
}

function list_themes() {
    for THEME in $(ls $THEMES_DIR); do
        THEME_NAME=`echo $THEME | sed s/\.zsh-theme$//`
        echo $THEME_NAME
    done
}

function insert_favlist() {
    if grep -q "$THEME_NAME" $FAVLIST 2> /dev/null ; then
        echo "Already in favlist"
    else
        echo $THEME_NAME >> $FAVLIST
        echo "Saved to favlist"
    fi

}
fox's avatar
fox committed
65

66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
function theme_chooser() {
    for THEME in $(ls $THEMES_DIR); do
        echo
        theme_preview $THEME
        echo
        if [[ -z $1 ]]; then
            noyes "Do you want to add it to your favourite list ($FAVLIST)?" || \
                  insert_favlist $THEME_NAME
            echo
        fi
    done
}

while getopts ":lhs" Option
do
  case $Option in
    l ) list_themes ;;
    s ) theme_chooser 0 ;;
    h ) usage ;;
    * ) usage ;; # Default.
  esac
fox's avatar
fox committed
87
done
88
89
90
91
92
93
94
95
96
97

if [[ -z $Option ]]; then
    if [[ -z $1 ]]; then
        banner
        echo
        theme_chooser
    else
        theme_preview $1".zsh-theme"
    fi
fi