Skip to content

Commit 494fecc

Browse files
Code & Features Update
1 parent 9e55ff7 commit 494fecc

1 file changed

Lines changed: 204 additions & 30 deletions

File tree

‎bash-function-icons‎

Lines changed: 204 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -4,57 +4,231 @@
44

55
# icons ────────────────────────────────────────────────────────────────────────
66

7+
icons_process_stop () {
8+
9+
# use to stop processes until none are left
10+
11+
local option_match
12+
local pattern_process
13+
local ids_process
14+
15+
option_match="${1}"
16+
pattern_process="${2}"
17+
18+
ids_process="$(command pgrep "${option_match}" -u "${USER}" "${pattern_process}")"
19+
20+
if [ -n "${ids_process}" ]
21+
then
22+
frobulator.inf "Stopping" "[ ${pattern_process##*/} ]"
23+
fi
24+
25+
while [ -n "${ids_process}" ]
26+
do
27+
command pkill "${option_match}" -u "${USER}" "${pattern_process}"
28+
29+
ids_process="$(command pgrep "${option_match}" -u "${USER}" "${pattern_process}")"
30+
done
31+
32+
}
33+
734
icons () {
835

9-
local list_directories_icons
36+
# use to reset icon and thumbnail caches
37+
38+
local file_index
39+
local directory_cache
40+
local directory_thumbnails
41+
local pattern_icons
42+
local pattern_services
43+
local pattern_theme
44+
local pattern_elements
45+
local pattern_thumbnailer
46+
local name_shell
47+
local option_full
48+
local option_exact
49+
local option_full_line
1050
local directory_icons
1151
local directory_theme
1252
local name_theme
13-
local file_index
14-
local directory_user
15-
local directory_prefix
16-
local directory_system
53+
local status_update
54+
local command_build
55+
local command_quit
56+
local command_start
57+
local name_manager
58+
local pattern_cache
59+
local file_cache
60+
local id_shell
61+
62+
local -a list_directories_icons
63+
local -a list_managers
64+
local -a list_patterns
65+
local -a list_themes
66+
local -a list_found
67+
local -a list_caches
1768

1869
file_index="index.theme"
19-
directory_user="${HOME}/.icons"
20-
directory_prefix="${PREFIX}/share/icons"
21-
directory_system="/usr/share/icons"
70+
directory_cache="${XDG_CACHE_HOME:-${HOME}/.cache}"
71+
directory_thumbnails="${directory_cache}/thumbnails"
72+
pattern_icons="icon-cache.kcache"
73+
pattern_services="ksycoca*"
74+
pattern_theme="plasma_theme_*.kcache"
75+
pattern_elements="plasma-svgelements*"
76+
pattern_thumbnailer="kio/thumbnail.so"
77+
name_shell="plasmashell"
78+
option_full="--noincremental"
79+
option_exact="-x"
80+
option_full_line="-f"
81+
82+
list_directories_icons=(
83+
"${HOME}/.icons"
84+
"${HOME}/.local/share/icons"
85+
"${PREFIX}/share/icons"
86+
"/usr/share/icons"
87+
)
88+
89+
list_managers=(
90+
"dolphin"
91+
"nautilus"
92+
"nemo"
93+
"caja"
94+
"thunar"
95+
"pcmanfm"
96+
)
97+
98+
list_patterns=(
99+
"${pattern_icons}"
100+
"${pattern_services}"
101+
"${pattern_theme}"
102+
"${pattern_elements}"
103+
)
104+
105+
list_caches=()
22106

23107
# output starts one line below the command
24108

25109
echo
26110

27111
frobulator.require gtk-update-icon-cache
28112

29-
list_directories_icons=(
30-
"${directory_user}"
31-
"${directory_prefix}"
32-
"${directory_system}"
33-
)
113+
# close file managers holding thumbnails
34114

35-
for directory_icons in ${list_directories_icons[@]}
115+
for name_manager in "${list_managers[@]}"
36116
do
37-
if [ -d "${directory_icons}" ]
117+
icons_process_stop "${option_exact}" "${name_manager}"
118+
done
119+
120+
# stop kde thumbnail workers
121+
122+
icons_process_stop "${option_full_line}" "${pattern_thumbnailer}"
123+
124+
# update icon theme caches
125+
126+
for directory_icons in "${list_directories_icons[@]}"
127+
do
128+
if [ ! -d "${directory_icons}" ]
38129
then
39-
cd "${directory_icons}"
130+
continue
40131
fi
41132

42-
if [ -d "${directory_icons}" ]
43-
then
44-
find "${directory_icons}" -mindepth 1 -maxdepth 1 -type d | while read -r directory_theme
45-
do
46-
name_theme="${directory_theme##*/}"
133+
mapfile -t list_themes < <(find "${directory_icons}" -mindepth 1 -maxdepth 1 -type d)
47134

48-
if [ -f "${directory_theme}/${file_index}" ]
49-
then
135+
for directory_theme in "${list_themes[@]}"
136+
do
137+
name_theme="${directory_theme##*/}"
50138

51-
gtk-update-icon-cache -f -q "${directory_theme}"
139+
if [ ! -f "${directory_theme}/${file_index}" ]
140+
then
141+
frobulator.wrn "Skipping" "[ ${name_theme} ]"
142+
143+
continue
144+
fi
145+
146+
if [ ! -w "${directory_theme}" ]
147+
then
148+
frobulator.wrn "Superuser needed" "[ ${directory_theme} ]"
149+
150+
continue
151+
fi
152+
153+
gtk-update-icon-cache -f -q "${directory_theme}" > "${sink}" 2>&1
154+
155+
status_update="${?}"
156+
157+
if [ "${status_update}" -eq 0 ]
158+
then
159+
frobulator.scs "Cache update success" "[ ${name_theme} ]"
160+
else
161+
frobulator.wrn "Cache update failed" "[ ${directory_theme} ]"
162+
fi
163+
164+
done
52165

53-
frobulator.scs "Cache update success" "[ ${name_theme} ]"
54-
else
55-
frobulator.wrn "Skipping" "[ ${name_theme} ]"
56-
fi
57-
done
58-
fi
59166
done
167+
168+
# kde caches when present
169+
170+
for pattern_cache in "${list_patterns[@]}"
171+
do
172+
mapfile -t list_found < <(find "${directory_cache}" -mindepth 1 -maxdepth 1 -name "${pattern_cache}")
173+
174+
list_caches+=("${list_found[@]}")
175+
done
176+
177+
# stored thumbnails
178+
179+
if [ -d "${directory_thumbnails}" ]
180+
then
181+
mapfile -t list_found < <(find "${directory_thumbnails}" -mindepth 1 -maxdepth 1)
182+
183+
list_caches+=("${list_found[@]}")
184+
fi
185+
186+
for file_cache in "${list_caches[@]}"
187+
do
188+
gio trash "${file_cache}"
189+
190+
frobulator.scs "Cache trashed" "[ ${file_cache#${directory_cache}/} ]"
191+
done
192+
193+
# plasma 6 helpers first
194+
195+
command_build="$(command -v kbuildsycoca6)"
196+
command_quit="$(command -v kquitapp6)"
197+
command_start="$(command -v kstart)"
198+
199+
# plasma 5 otherwise
200+
201+
if [ -z "${command_build}" ]
202+
then
203+
command_build="$(command -v kbuildsycoca5)"
204+
command_quit="$(command -v kquitapp5)"
205+
command_start="$(command -v kstart5)"
206+
fi
207+
208+
# rebuild kde service cache
209+
210+
if [ -n "${command_build}" ]
211+
then
212+
"${command_build}" "${option_full}" > "${sink}" 2>&1
213+
214+
frobulator.scs "Service cache rebuilt" "[ ${command_build##*/} ]"
215+
fi
216+
217+
# restart plasma shell when running
218+
219+
id_shell="$(command pgrep -x -u "${USER}" "${name_shell}")"
220+
221+
if [ -n "${id_shell}" ] &&
222+
[ -n "${command_quit}" ] &&
223+
[ -n "${command_start}" ]
224+
then
225+
"${command_quit}" "${name_shell}" > "${sink}" 2>&1
226+
227+
# detached from this shell
228+
229+
( "${command_start}" "${name_shell}" < /dev/null > "${sink}" 2>&1 & )
230+
231+
frobulator.scs "Shell restarted" "[ ${name_shell} ]"
232+
fi
233+
60234
}

0 commit comments

Comments
 (0)