This repository has been archived by the owner on Aug 20, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 21
/
tstyle
executable file
·226 lines (198 loc) · 9.02 KB
/
tstyle
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
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
#!/usr/bin/env bash
## Author : Aditya Shakya
## Twitter : @adi1090x
## Github : @adi1090x
## Reddit : @adi1090x
## A simple script to change color-schemes & fonts of termite.
## ANSI Colors (FG & BG)
RED="$(printf '\033[31m')" GREEN="$(printf '\033[32m')" ORANGE="$(printf '\033[33m')" BLUE="$(printf '\033[34m')"
MAGENTA="$(printf '\033[35m')" CYAN="$(printf '\033[36m')" WHITE="$(printf '\033[37m')" BLACK="$(printf '\033[30m')"
REDBG="$(printf '\033[41m')" GREENBG="$(printf '\033[42m')" ORANGEBG="$(printf '\033[43m')" BLUEBG="$(printf '\033[44m')"
MAGENTABG="$(printf '\033[45m')" CYANBG="$(printf '\033[46m')" WHITEBG="$(printf '\033[47m')" BLACKBG="$(printf '\033[40m')"
## Directories
TERMITE_DIR="$HOME/.config/termite"
COLORS_DIR='/usr/share/termite-style/colors'
FONTS_DIR='/usr/share/fonts/termite-style'
## Banner
banner () {
clear
echo "
${RED}┌──────────────────────────────────────────────────────┐
│░░░▀█▀░█▀▀░█▀▄░█▄█░▀█▀░▀█▀░█▀▀░░░█▀▀░▀█▀░█░█░█░░░█▀▀░░│
│░░░░█░░█▀▀░█▀▄░█░█░░█░░░█░░█▀▀░░░▀▀█░░█░░░█░░█░░░█▀▀░░│
│░░░░▀░░▀▀▀░▀░▀░▀░▀░▀▀▀░░▀░░▀▀▀░░░▀▀▀░░▀░░░▀░░▀▀▀░▀▀▀░░│
└──────────────────────────────────────────────────────┘
${ORANGE}[*] ${CYAN}By- Aditya Shakya // adi1090x"
}
## Script Termination
exit_on_signal_SIGINT () {
{ printf "${RED}\n\n%s\n" " [*] Script interrupted." 2>&1; echo; reset_color; }
exit 0
}
exit_on_signal_SIGTERM () {
{ printf "${RED}\n\n%s\n" " [*] Script terminated." 2>&1; echo; reset_color; }
exit 0
}
trap exit_on_signal_SIGINT SIGINT
trap exit_on_signal_SIGTERM SIGTERM
## Reset terminal colors
reset_color() {
tput sgr0 # reset attributes
tput op # reset color
return
}
## Available color-schemes & fonts
check_files () {
if [[ "$1" = colors ]]; then
colors=($(ls $COLORS_DIR))
echo ${#colors[@]}
elif [[ "$1" = fonts ]]; then
fonts=($(ls $FONTS_DIR))
echo ${#fonts[@]}
fi
return
}
total_colors=$(check_files colors)
total_fonts=$(check_files fonts)
## Reload Settings
reload_settings () {
echo "${MAGENTA} [*] Reloading Settings..."
killall -USR1 termite > /dev/null
{ echo "${CYAN} [*] Applied Successfully."; echo; }
return
}
## Apply color-schemes
apply_colors () {
local count=1
# List the color-schemes
color_schemes=($(ls $COLORS_DIR))
for colors in "${color_schemes[@]}"; do
colors_name=$(echo $colors)
echo ${ORANGE}" [$count] ${colors_name%.*}"
count=$(($count+1))
done
# Read user selection
{ echo; read -p ${GREEN}" [Select Color Scheme (1 to $total_colors)]: ${BLUE}" answer; echo; }
# Apply color-scheme
if [[ (-n "$answer") && ("$answer" -le $total_colors) ]]; then
scheme=${color_schemes[(( answer - 1 ))]}
echo "${ORANGE} [*] Applying Color Scheme..."
sed -i '/colors/Q' $TERMITE_DIR/config
cat $COLORS_DIR/$scheme >> $TERMITE_DIR/config
{ reload_settings; reset_color; exit; }
else
echo -n "${RED} [!] Invalid Option, Try Again."
{ sleep 2; banner; echo; apply_colors; }
fi
return
}
## Apply fonts
apply_fonts () {
local count=1
# List fonts
fonts_list=($(ls $FONTS_DIR))
for fonts in "${fonts_list[@]}"; do
fonts_name=$(echo $fonts)
echo ${ORANGE}" [$count] ${fonts_name%.*}"
count=$(($count+1))
done
# Read user selection
{ echo; read -p ${GREEN}" [Select font (1 to $total_fonts)]: ${BLUE}" answer; echo; }
# Apply fonts
if [[ (-n "$answer") && ("$answer" -le $total_fonts) ]]; then
font_ttf=${fonts_list[(( answer - 1 ))]}
actual_font_name=$(fc-list | grep -i $font_ttf | head -n 1 | cut -d':' -f2)
{ read -p ${GREEN}" [Enter Font Size (Default is 10)]: ${BLUE}" font_size; echo; }
echo "${ORANGE} [*] Applying Fonts..."
sed -i -e "s/font = .*/font = $actual_font_name ${font_size:-10}/g" $TERMITE_DIR/config
{ reload_settings; reset_color; exit; }
else
echo -n "${RED} [!] Invalid Option, Try Again."
{ sleep 2; banner; echo; apply_fonts; }
fi
return
}
## Random style
random_style () {
echo ${ORANGE}" [*] Setting Random Style..."
random_scheme=$(ls $COLORS_DIR | shuf -n 1)
{ sed -i '/colors/Q' $TERMITE_DIR/config; cat $COLORS_DIR/$random_scheme >> $TERMITE_DIR/config; }
{ reload_settings; reset_color; exit; }
}
## Import files
import_files () {
echo "${ORANGE} [1] Local File (Enter path to file)
${CYAN}[2] Internet File (Enter File URL)"
{ echo; read -p ${GREEN}" [Select Option]: ${BLUE}" option; echo; }
temp_file=$(mktemp /tmp/tstyle_XXXXXXXXXX.config)
if [[ "$option" =~ ^[1,2]$ ]]; then
if [[ "$option" == 1 ]]; then
{ read -p ${GREEN}" [Enter Path To Color-scheme]: ${BLUE}" file_path; echo; }
sed -i '/colors/Q' $TERMITE_DIR/config
cat $file_path >> $TERMITE_DIR/config
{ reload_settings; reset_color; exit; }
elif [[ "$option" == 2 ]]; then
{ read -p ${GREEN}" [Enter Color-scheme URL]: ${BLUE}" file_link; echo; }
wget -o /tmp/log -O $temp_file $file_link
sed -i '/colors/Q' $TERMITE_DIR/config
cat $temp_file >> $TERMITE_DIR/config
{ reload_settings; reset_color; exit; }
fi
else
echo -n "${RED} [!] Invalid Option, Try Again."
{ sleep 2; banner; echo; import_files; }
fi
}
## About program
about_program () {
echo -n ${BLUE}" ┌───────────────────────────────────────────────────────────────┐
│ ┏━┓┏┓ ┏━┓╻ ╻╺┳╸ ╺┳╸┏━╸┏━┓┏┳┓╻╺┳╸┏━╸ ┏━┓╺┳╸╻ ╻╻ ┏━╸ │
│ ┣━┫┣┻┓┃ ┃┃ ┃ ┃ ╹ ┃ ┣╸ ┣┳┛┃┃┃┃ ┃ ┣╸ ┗━┓ ┃ ┗┳┛┃ ┣╸ │
│ ╹ ╹┗━┛┗━┛┗━┛ ╹ ╹ ╹ ┗━╸╹┗╸╹ ╹╹ ╹ ┗━╸ ┗━┛ ╹ ╹ ┗━╸┗━╸ │
│───────────────────────────────────────────────────────────────│
│ │
│ >> 'termite-style' is a simple program that provides color │
│ schemes and powerline-ready fonts to customize the │
│ appearance of the termite terminal. │
│ │
│ │
│ >> Author : Aditya Shakya │
│ Email : [email protected] │
│ Github : https://github.com/adi1090x │
│ Twitter : https://twitter.com/adi1090x │
│ │
│───────────────────────────────────────────────────────────────│
│ GNU GENERAL PUBLIC LICENSE VERSION 3 │
└───────────────────────────────────────────────────────────────┘"
{ echo; read -p ${GREEN}" [*] Press 'Enter' To Return To Main Menu."; }
}
## Main menu
while [[ "$REPLY" != 0 ]]; do
banner
echo "
${RED}[1] Colors ($total_colors)
${GREEN}[2] Fonts ($total_fonts)
${ORANGE}[3] Random
${BLUE}[4] Import
${MAGENTA}[5] About
${CYAN}[0] Quit
"
{ read -p ${GREEN}" [Select Option]: ${BLUE}"; echo; }
if [[ "$REPLY" =~ ^[0-5]$ ]]; then #validate input
if [[ "$REPLY" == 1 ]]; then
apply_colors
elif [[ "$REPLY" == 2 ]]; then
apply_fonts
elif [[ "$REPLY" == 3 ]]; then
random_style
elif [[ "$REPLY" == 4 ]]; then
import_files
elif [[ "$REPLY" == 5 ]]; then
about_program
fi
else
echo -n "${RED} [!] Invalid Option, Try Again."
sleep 2
fi
done
{ echo "${RED} [*] Bye Bye, Have A Nice Day!"; echo; reset_color; }