-
-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathTemplateManagerTools.sh
77 lines (66 loc) · 1.95 KB
/
TemplateManagerTools.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
70
71
72
73
74
75
76
77
#!/bin/bash
# region Shared constants
creator_icon="favorite"
editor_icon="edit"
eraser_icon="delete"
desktop_ext=".desktop"
bin_dir="$HOME/.bin/"
if [ "$(xdg-user-dir TEMPLATES)" != "$HOME" ]; then
template_folder="$(xdg-user-dir TEMPLATES)"
else
IFS=':' read -ra template_installation_paths <<< "$(kf5-config --path templates)"
counter=0
unset template_folder
while [ $counter -lt ${#template_installation_paths[@]} ] && [ -z "$template_folder" ]; do
path="$(realpath "${template_installation_paths[$counter]}")"
if [ "${path##$HOME}" != "${path}" ]; then
template_folder="$path"
fi
((counter++))
done
fi
template_src_folder="$template_folder/source"
IFS=':' read -ra service_installation_paths <<< "$(kf5-config --path services)"
counter=0
unset service_folder
while [ $counter -lt ${#service_installation_paths[@]} ] && [ -z "$service_folder" ]; do
path="$(realpath "${service_installation_paths[$counter]}")"
if [ "${path##$HOME}" != "${path}" ]; then
if [ -e "$path/ServiceMenus" ]; then
service_folder="$path/ServiceMenus"
else
service_folder="$path"
fi
fi
((counter++))
done
# endregion
# region Shared functions
function get_filename() # (filePath: str)
{
basename -- "$1"
}
function get_filename_wo_extension() # (filePath: str)
{
local filename
filename="$(get_filename "$1")"
if [ ! -d "$1" ]; then
filename="${filename%.*}"
fi
printf "%s" "$filename"
}
function get_file_extension() # (filePath: str)
{
local filename filename_wo_extension ext
filename="$(get_filename "$1")"
filename_wo_extension="$(get_filename_wo_extension "$1")"
ext="${filename#$filename_wo_extension}"
printf "%s" "$ext"
}
function get_template_desktop_path() # (templatePath: str)
{
local path
path="$template_folder/$(get_filename_wo_extension "$1")$desktop_ext"
printf "%s" "$path"
}
# endregion