-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathsetup.sh
executable file
·110 lines (90 loc) · 2.22 KB
/
setup.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
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
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
#!/bin/env bash
# Usage:
# $ ./setup.sh
USAGE="Usage: setup.sh [-h|--help]"
HELP="\
setup.sh
Commands:
-h, --help print this help message
A script to set up termite config to work"
SUCCESS_INFO="\
Your termite config ~/.config/termite/config has been split into two other
configs (~/.config/termite/option && ~/.config/termite/color/default) which you
should use to edit your settings from now on because the original file
(~/.config/termite/config) will be overwrite when using the color command
The ~/.config/termite/color/default stores info in the color section and the
~/.config/termite/option stores the rest of the config (options and hints
section)."
set -o errexit
set -o pipefail
set -o nounset
# set -o xtrace
function die () {
echo "$*" >&2
exit 1
}
function usage() {
die "$USAGE"
}
function help() {
echo "$HELP"
}
function backup_config() {
cp "$CONFIG" "$BACKUP_CONFIG"
}
function set_current_colorscheme() {
local color_name="$1"
echo "$color_name" > "$THEME"
}
function print_info() {
echo "$SUCCESS_INFO"
}
function split_config_into_two() {
backup_config
mkdir -p "$COLOR_PATH"
local color_section=false
while read -r line || [[ -n "$line" ]]; do
if [[ "$line" =~ ^\[colors\]$ ]]; then
color_section=true
elif [[ "$line" =~ ^\[(hints|options)\]$ ]]; then
color_section=false
fi
if [[ "$color_section" == true ]]; then
echo "$line" >> "$COLOR_PATH"/default
elif [[ "$color_section" == false ]]; then
echo "$line" >> "$OPTION"
fi
done < "$BACKUP_CONFIG"
print_info
}
function add_sample_colorschemes() {
[[ -d "$COLOR_PATH" ]] || mkdir -p "$COLOR_PATH"
cp color/* "$COLOR_PATH"
}
function setup() {
[[ ! -f "$CONFIG" ]] && die 'termite config ~/.config/termite/config not exists'
set_current_colorscheme 'default'
split_config_into_two
add_sample_colorschemes
}
function main() {
local termite_path="$HOME"'/.config/termite'
local OPTION="$termite_path"'/option'
local CONFIG="$termite_path"'/config'
local BACKUP_CONFIG="$termite_path"'/config.backup'
local THEME="$termite_path"'/theme'
local COLOR_PATH="$termite_path"'/color'
local flag="$@"
case "$#" in
0)
setup ;;
*)
case "$flag" in
-h|--help)
help ;;
*)
usage ;;
esac
esac
}
main "$@"