-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathtel-theme
executable file
·235 lines (222 loc) · 6.75 KB
/
tel-theme
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
227
228
229
230
231
232
233
234
235
#!/usr/bin/env bash
### TEL THEME MANAGER ###
# sealyj 2021 #
version=0.2
FZF_DEFAULT_COMMAND='fd --type f --hidden --follow --exclude .git'
wallpaper_folder=~/.tel/theme/active/wallpaper
themes_folder=~/.tel/theme/inactive
active_theme=~/.tel/theme/active
show_help(){
printf "%s\n"\
"theme and wallpaper manager"\
"tel-theme [OPTIONS] [PATTERN]"\
"__________________________"\
"OPTIONS"\
" -a | --apply pick + apply a theme from your currently installed themes"\
" -f | --file auto-gen theme based on an image"\
" -i | --install install a TEL theme file package"\
" -c | --create collect and package current files into a theme file"\
" -t | --theme apply a preconfigured palette (run without args to see list of availible)"\
" -w | --wallpaper apply a wallpaper only"\
" --alpha set background alpha eg FF"\
" -h | --help display this help message"
}
spinner() {
# Spinner animation #
# line before calling spinner() must spawn bg process: eg echo hi;sleep 2 &;spinner
# show working spinner
PID=$!
i=1
sp="/-\|"
echo -n ' '
while [ -d /proc/$PID ]
do
echo -ne "\b${sp:i++%${#sp}:1}"
sleep 0.1
done
echo -ne "\b${CHECK_MARK}" #remove last spinner
}
restart_tel(){
tel-restart
printf "\n\e[33;5;2m Theme\e[m%s press [Return] to restart + apply changes..\n"
read
tel-restart
}
install_theme(){
selected_theme=$(fd --ignore-case --absolute-path --type f | fzf -e --color=16 --query="$file_search" --prompt="Pick a theme to apply: " --select-1)
printf "\e[33;5;2m Theme\e[m%s installing theme file: $selected_theme\n"
cp -f $selected_theme $themes_folder
printf "\e[33;5;2m Theme\e[m%s installed theme: $selected_theme\n"
}
create_theme(){
printf "\e[33;5;2m Theme\e[m%s packaging current files into theme\n"
rm -rf $TMPDIR/tel-theme/* > /dev/null 2>&1
mkdir -p $TMPDIR/tel-theme/packaging/configs
mkdir -p $TMPDIR/tel-theme/packaging/wallpaper
mkdir -p $TMPDIR/tel-theme/packaging/termux
cd $TMPDIR/tel-theme/packaging
mkdir -p ~/.tel/theme/inactive >/dev/null
cp ~/.tel/theme/active/wallpaper/*.jpg ./wallpaper/
cp ~/.tel/theme/active/colors.sh .
cp ~/.tel/configs/theme.conf ./configs/
cp ~/.termux/termux.properties ./termux
printf "\e[33;5;2m Theme\e[m%s Enter name for new theme: "
while [ -z "$new_theme_name" ] ; do
read new_theme_name
done
printf "\e[33;5;2m Theme\e[m%s Enter name of author: "
read author_theme_name
tar -v -c -z -f $themes_folder/${new_theme_name}.tar.gz . >&/dev/null &
spinner
printf "\e[33;5;2m Theme\e[m finished! \n theme to: $themes_folder/${new_theme_name}"
}
auto_theme(){
FZF_DEFAULT_OPTS="
--info=inline
--multi
--preview-window=up:60%:follow:sharp
--preview '([[ -f {} ]] && (termimage --size=35x35 {} || bat --theme=base16 --style=numbers --color=always {} || cat {})) || ([[ -d {} ]] && (tree -C {} | less)) || echo {} 2> /dev/null | head -200'
--prompt='∼ ' --pointer='>' --marker='✓'
--bind '?:toggle-preview'
--bind 'ctrl-a:select-all'
--bind 'ctrl-y:execute-silent(echo {+} | pbcopy)'
"
cd ~
if [ -z "$@" ] ; then
file_search="$@"
else
file_search=".jpg"
fi
selected_file=$(fd --extension=jpg -e png --follow --absolute-path --hidden --type f | fzf --color=16 --query="$file_search" --prompt="Pick a image to theme from: " --select-1)
if [ -z $selected_file ] ; then
exit 1
fi
printf "\e[33;5;2m Theme\e[m%s extracting colorscheme from: $selected_file "
(wal -i "$selected_file" -n -q -s -t -e || (echo 'failed to get colors from file' ; exit 1)) &
spinner
cp -rf ~/.cache/wal/colors.sh ~/.tel/theme/active/
mkdir -p ~/.tel/theme/active/wallpaper >/dev/null 2>&1
rm -rf ~/.tel/theme/active/wallpaper/* > /dev/null 2>&1
cp "$selected_file" ~/.tel/theme/active/wallpaper/
touch ~/.tel/theme/.flag
# add flag for setting wallpaper on reboot
~/.tel/scripts/apply_colors.sh # propagate colors
restart_tel
}
wal_theme(){
selected_wal_theme=$(cat ~/.tel/theme/wal_themes | fzf -e --color=16 --query="$@" --prompt="Pick a theme to apply: " --select-1)
if [ ! -z "$selected_wal_theme" ] ; then
wal --theme $selected_wal_theme -n -e -t -s
cp -f ~/.cache/wal/colors.sh ~/.tel/theme/active/
~/.tel/scripts/apply_colors.sh -a FF # propagate colors, -a FF is alpha channel
tel-restart
else
exit 1
fi
}
set_bg_alpha(){
alpha=$1
if [ -z $1 ] ; then
printf "\e[33;5;2m Theme\e[m%s please supply 2 hexidecimal characters "
exit 1
fi
~/.tel/scripts/apply_colors.sh -a $alpha # propagate colors, -a FF is alpha channel
printf "\e[33;5;2m Theme\e[m%s alpha set, restart to see changes"
}
apply_theme(){
cd $themes_folder
file_search="$@"
selected_file=$(fd --exclude .git --ignore-case --type f | fzf -e --color=16 --query="$file_search" --prompt="Pick a theme to apply: " --select-1)
if [ -z $selected_file ] ; then
exit 1
fi
printf "\e[33;5;2m Theme\e[m%s applying: $selected_file "
#unzip
cd
rm -rf $active_theme >/dev/null
mkdir $active_theme
cd $active_theme
tar -x -U -f $themes_folder/$selected_file . &
spinner
touch ~/.tel/theme/.flag
# add flag for setting wallpaper on reboot
~/.tel/scripts/apply_colors.sh #propagate colors
printf "\n\e[33;5;2m Theme\e[m%s finished applying: $selected_file "
restart_tel
}
apply_wallpaper(){
FZF_DEFAULT_OPTS="
--info=inline
--multi
--preview-window=up:60%:follow:sharp
--preview '([[ -f {} ]] && (termimage --size=35x35 {} || bat --theme=base16 --style=numbers --color=always {} || cat {})) || ([[ -d {} ]] && (tree -C {} | less)) || echo {} 2> /dev/null | head -200'
--prompt='∼ ' --pointer='>' --marker='✓'
--bind '?:toggle-preview'
--bind 'ctrl-a:select-all'
--bind 'ctrl-y:execute-silent(echo {+} | pbcopy)'
"
cd ~
if [ -z "$@" ] ; then
file_search="$@"
else
file_search=".jpg"
fi
selected_file=$(fd --extension=jpg -e png --follow --absolute-path --type f | fzf --color=16 --query="$file_search" --prompt="Pick a image to set as wallpaper: " --select-1)
if [ -z $selected_file ] ; then
exit 1
fi
printf "\e[33;5;2m Theme\e[m%s applying wallpaper: $selected_file "
termux-wallpaper -f "$selected_file" || echo "Failed to apply $selected_file"
}
main(){
case "$1" in
-v | --version)
printf "\n\e[33;5;2m Theme\e[m%s version: $version"
exit 0
;;
-a | --apply)
shift
apply_theme
exit 0
;;
-f | --file)
shift
auto_theme
exit 0
;;
-i | --install)
install_theme
exit 0
;;
-c | --create)
create_theme
#read WAL wallpaper
exit 0
;;
-t | --theme)
shift
wal_theme "$@"
exit 0
;;
-w | --wallpaper)
shift
apply_wallpaper "$@"
exit 0
;;
--alpha)
shift
set_bg_alpha "$@"
exit 0
;;
# Display the help message
-h | --help)
show_help
exit 0
;;
*)
show_help
exit 1
;;
esac
}
main $@