-
-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathTemplateEraser.sh
executable file
·69 lines (54 loc) · 1.95 KB
/
TemplateEraser.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
#!/bin/bash
# shellcheck source=./TemplateManagerLocalization.sh
. "$HOME/.bin/TemplateManagerLocalization.sh"
# shellcheck source=./TemplateManagerTools.sh
. "$HOME/.bin/TemplateManagerTools.sh"
function cancel_operation()
{
kdialog --error "$(str_cancel_operation)" --title "$(str_window_title)" --icon "$eraser_icon"
exit 1
}
function no_available_templates()
{
kdialog --error "$(str_no_available_templates)" --title "$(str_window_title)" --icon "$eraser_icon"
exit 1
}
function remove_template() # (currentTemplateFilename: str)
{
rm -r "${template_src_folder:?}/${1:?}" "$(get_template_desktop_path "$1")"
}
# region Main
if [ "$(find "$template_src_folder" -maxdepth 1 -mindepth 1 -printf '%P\n' | wc -l)" -eq 0 ]; then
no_available_templates
fi
declare -a kdialog_args
kdialog_args+=("$(str_select_templates_to_remove)")
for file in "$template_src_folder"/* ; do
if [ -e "$file" ] && [ -e "$(get_template_desktop_path "$file")" ]; then
filename="$(get_filename "$file")"
kdialog_args+=("$filename")
if [ -d "$file" ]; then
kdialog_args+=("🗂 $filename")
elif [ -f "$file" ]; then
kdialog_args+=("🗐 $filename")
else
kdialog_args+=("❓ $filename")
fi
kdialog_args+=("off")
fi
done
if ! templates_to_remove=$(kdialog --separate-output --checklist "${kdialog_args[@]}" --title "$(str_window_title)" --icon "$eraser_icon" --geometry 500x500); then
cancel_operation
fi
file_list=""
while IFS= read -r file; do
file_list="$file_list<br>- $file"
done <<< "$templates_to_remove"
if ! kdialog --warningyesno "$(str_remove_confirmation)$file_list" --title "$(str_window_title)" --icon "$eraser_icon"; then
cancel_operation
fi
while IFS= read -r file; do
remove_template "$file"
done <<< "$templates_to_remove"
kdialog --msgbox "$(str_removed_templates)$file_list" --title "$(str_window_title)" --icon "$eraser_icon"
# endregion