-
-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathTemplateCreator.sh
executable file
·65 lines (50 loc) · 1.91 KB
/
TemplateCreator.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
#!/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 "$creator_icon"
exit 1
}
function cannot_template()
{
kdialog --error "$(str_cannot_template)" --title "$(str_window_title)" --icon "$creator_icon"
exit 1
}
function exists_template_with_same_name()
{
kdialog --error "$(str_exists_template_with_same_name)" --title "$(str_window_title)" --icon "$creator_icon"
}
# region Main
if [ "$#" -ne 1 ]; then
printf "Error: Illegal number of parameters.\nUse: sh %s <file/directory>\n" "$0"
exit 1
elif [ ! -d "$1" ] && [ ! -f "$1" ]; then
cannot_template
fi
shortname="$(get_filename_wo_extension "$1")"
if ! template_name=$(kdialog --inputbox "$(str_get_name)" "$shortname" --title "$(str_window_title)" --icon "$creator_icon" --geometry 450x300); then
cancel_operation
elif [ -z "${template_name// /}" ]; then
template_name=$shortname
elif does_template_exist_with_same_name "${CONFIG["URL"]}" "$template_name"; then
exists_template_with_same_name
fi
if ! template_comment=$(kdialog --inputbox "$(str_get_comment)" --title "$(str_window_title)" --icon "$creator_icon"); then
cancel_operation
fi
if ! template_icon=$(kdialog --geticon MimeType --title "$(str_window_title)" --icon "$creator_icon"); then
cancel_operation
fi
template_url="$template_src_folder/$template_name$(get_file_extension "$1")"
/bin/cp -r "$1" "$template_url"
printf "[Desktop Entry]
Name=%s
Comment=%s
Type=Link
URL=%s
Icon=%s" "$template_name" "$template_comment" "$template_url" "$template_icon" > "$template_folder/$template_name$desktop_ext"
kdialog --msgbox "$(str_created_template)'$template_name'." --title "$(str_window_title)" --icon "$creator_icon"
# endregion