forked from adi1090x/termux-style
-
Notifications
You must be signed in to change notification settings - Fork 0
/
tstyle
executable file
·221 lines (193 loc) · 9.03 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
#!/data/data/com.termux/files/usr/bin/bash
## Author : Aditya Shakya
## Twitter : @adi1090x
## Github : @adi1090x
## Reddit : @adi1090x
## A simple script to change color-schemes & fonts of termux terminal emulator.
## 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')"
DEFAULT_FG="$(printf '\033[39m')" DEFAULT_BG="$(printf '\033[49m')"
## Directories
PREFIX='/data/data/com.termux/files/usr'
TERMUX_DIR="$HOME/.termux"
COLORS_DIR="$PREFIX/share/termux-style/colors"
FONTS_DIR="$PREFIX/share/termux-style/fonts"
## Banner
banner () {
clear
echo "
${BLUE}┌──────────────────────────────────────────────────┐
${BLUE}│${RED}░▀█▀░█▀▀░█▀▄░█▄█░█░█░█░█${ORANGE}░░░░░${GREEN}█▀▀░▀█▀░█░█░█░░░█▀▀░░${BLUE}│
${BLUE}│${RED}░░█░░█▀▀░█▀▄░█░█░█░█░▄▀▄${ORANGE}░▄▄▄${RED}░${GREEN}▀▀█░░█░░░█░░█░░░█▀▀░░${BLUE}│
${BLUE}│${RED}░░▀░░▀▀▀░▀░▀░▀░▀░▀▀▀░▀░▀${ORANGE}░░░░░${GREEN}▀▀▀░░▀░░░▀░░▀▀▀░▀▀▀░░${BLUE}│
${BLUE}└──────────────────────────────────────────────────┘
${BLUE}[${RED}*${BLUE}] ${ORANGE}By- Aditya Shakya ${RED}//${ORANGE} adi1090x"
}
## Script Termination
exit_on_signal_SIGINT () {
{ printf "\n\n%s\n" " ${BLUE}[${RED}*${BLUE}] ${RED}Script interrupted." 2>&1; echo; reset_color; }
exit 0
}
exit_on_signal_SIGTERM () {
{ printf "\n\n%s\n" " ${BLUE}[${RED}*${BLUE}] ${RED}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 " ${BLUE}[${RED}*${BLUE}] ${MAGENTA}Reloading Settings..."
am broadcast --user 0 -a com.termux.app.reload_style com.termux > /dev/null
{ echo " ${BLUE}[${RED}*${BLUE}] ${GREEN}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 ${BLUE}" [${RED}Select Color Scheme (1 to $total_colors)${BLUE}]: ${GREEN}" answer; echo; }
# Apply color-scheme
if [[ (-n "$answer") && ("$answer" -le $total_colors) ]]; then
scheme=${color_schemes[(( answer - 1 ))]}
echo " ${BLUE}[${RED}*${BLUE}] ${ORANGE}Applying Color Scheme..."
cp $COLORS_DIR/$scheme $TERMUX_DIR/colors.properties
{ reload_settings; reset_color; exit; }
else
echo -n " ${BLUE}[${RED}!${BLUE}] ${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 ${BLUE}" [${RED}Select font (1 to $total_fonts)${BLUE}]: ${GREEN}" answer; echo; }
# Apply fonts
if [[ (-n "$answer") && ("$answer" -le $total_fonts) ]]; then
font_ttf=${fonts_list[(( answer - 1 ))]}
echo " ${BLUE}[${RED}*${BLUE}] ${ORANGE}Applying Fonts..."
cp $FONTS_DIR/$font_ttf $TERMUX_DIR/font.ttf
{ reload_settings; reset_color; exit; }
else
echo -n " ${BLUE}[${RED}!${BLUE}] ${RED}Invalid Option, Try Again."
{ sleep 2; banner; echo; apply_fonts; }
fi
return
}
## Random style
random_style () {
echo " ${BLUE}[${RED}*${BLUE}] ${ORANGE}Setting Random Style..."
random_scheme=$(ls $COLORS_DIR | shuf -n 1)
{ cp $COLORS_DIR/$random_scheme $TERMUX_DIR/colors.properties; }
{ reload_settings; reset_color; exit; }
}
## Import files
import_files () {
echo " ${BLUE}[${RED}L${BLUE}] ${ORANGE}Local File (Enter path to file)
${BLUE}[${RED}I${BLUE}] ${ORANGE}Internet File (Enter File URL)"
{ echo; read -p ${BLUE}" [${RED}Select Option${BLUE}]: ${GREEN}" option; echo; }
temp_file=$(mktemp $PREFIX/tmp/termux_XXXXXXXXXX.properties)
if [[ "$option" =~ ^[l/L/i/I]$ ]]; then
if [[ "$option" =~ ^[l/L]$ ]]; then
{ read -p ${BLUE}" [${RED}Enter/Paste Path To Color-scheme${BLUE}]: ${GREEN}" file_path; echo; }
cp $file_path $TERMUX_DIR/colors.properties
{ reload_settings; reset_color; exit; }
elif [[ "$option" =~ ^[i/I]$ ]]; then
{ read -p ${BLUE}" [${RED}Enter Color-scheme URL${BLUE}]: ${GREEN}" file_link; echo; }
wget -o $PREFIX/tmp/log -O $temp_file $file_link
cp $temp_file $TERMUX_DIR/colors.properties
{ reload_settings; reset_color; exit; }
fi
else
echo -n " ${BLUE}[${RED}!${BLUE}] ${RED}Invalid Option, Try Again."
{ sleep 2; banner; echo; import_files; }
fi
}
## About program
about_program () {
echo -n ${BLUE}" ┌───────────────────────────────────────────────────────────────┐
│ ┏━┓┏┓ ┏━┓╻ ╻╺┳╸ │
│ ┣━┫┣┻┓┃ ┃┃ ┃ ┃ │
│ ╹ ╹┗━┛┗━┛┗━┛ ╹ │
│───────────────────────────────────────────────────────────────│
│ │
│ >> 'termux-style' is a simple program that provides color │
│ schemes and powerline-ready fonts to customize the │
│ appearance of the termux terminal emulator. │
│ │
│ │
│ >> Author : Aditya Shakya │
│ Twitter : https://twitter.com/adi1090x │
│ Github : https://github.com/adi1090x │
│ Reddit : https://www.reddit.com/user/adi1090x │
│ │
└───────────────────────────────────────────────────────────────┘"
{ echo; read -p " ${BLUE}[${RED}*${BLUE}] ${GREEN}Press ${GREENBG}${BLACK} Enter ${DEFAULT_BG}${GREEN} To Return To Main Menu."; }
}
## Main menu
until [[ "$REPLY" =~ ^[q/Q]$ ]]; do
banner
echo "
${BLUE}[${RED}C${BLUE}] ${GREEN}Colors ($total_colors)
${BLUE}[${RED}F${BLUE}] ${GREEN}Fonts ($total_fonts)
${BLUE}[${RED}R${BLUE}] ${GREEN}Random
${BLUE}[${RED}I${BLUE}] ${GREEN}Import
${BLUE}[${RED}A${BLUE}] ${GREEN}About
${BLUE}[${RED}Q${BLUE}] ${GREEN}Quit
"
{ read -p ${BLUE}" [${RED}Select Option${BLUE}]: ${GREEN}"; echo; }
if [[ "$REPLY" =~ ^[c/C/f/F/r/R/i/I/a/A/q/Q]$ ]]; then #validate input
if [[ "$REPLY" =~ ^[c/C]$ ]]; then
apply_colors
elif [[ "$REPLY" =~ ^[f/F]$ ]]; then
apply_fonts
elif [[ "$REPLY" =~ ^[r/R]$ ]]; then
random_style
elif [[ "$REPLY" =~ ^[i/I]$ ]]; then
import_files
elif [[ "$REPLY" =~ ^[a/A]$ ]]; then
about_program
fi
else
echo -n " ${BLUE}[${RED}!${BLUE}] ${RED}Invalid Option, Try Again."
sleep 2
fi
done
{ echo " ${BLUE}[${RED}*${BLUE}] ${RED}Bye Bye, Have A Nice Day!"; echo; reset_color; exit 0; }