Skip to content

Commit 3586a26

Browse files
authored
Merge pull request #52 from AleixMT/dynamic_wrappers_#43
Dynamic wrappers #43
2 parents d77dbe2 + 17566dc commit 3586a26

File tree

10 files changed

+69
-40
lines changed

10 files changed

+69
-40
lines changed

data/core/common_data.sh

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -698,7 +698,8 @@ declare -r auxiliary_arguments=("-v" "-q" "-Q" "-s" "-o" "-e" "-i" "-d" "-c" "-C
698698
# multi-feature wrapper. #
699699
# Is preferable that the wrapper has the same installation privileges in all of its features. #
700700
########################################################################################################################
701-
declare -r WRAPPERS_KEYNAMES=("programmingcore" "programmingide" "programmingpro" "texteditorcore" "mediacore" "systemcore" "internetcore" "artcore" "gamesinstall" "internetshortcuts" "standardinstall" "bashfunctions" "desktopfunctions" "terminalfunctions" "network" "networks" "fontsuser" "fontsroot" "custom1" "gitbashfunctions" "iochemroot" "iochemuser")
701+
# TODO: static wrapper deprecated for dynamic wrappers. Now we must move the static wrappers that we want to keep into tags
702+
# declare -r WRAPPERS_KEYNAMES=("programmingcore" "programmingide" "programmingpro" "texteditorcore" "mediacore" "systemcore" "internetcore" "artcore" "gamesinstall" "internetshortcuts" "standardinstall" "bashfunctions" "desktopfunctions" "terminalfunctions" "network" "networks" "fontsuser" "fontsroot" "custom1" "gitbashfunctions" "iochemroot" "iochemuser")
702703
# Thematic wrappers
703704
declare -r wrapper_programmingcore=("python3" "gcc" "jdk11" "git" "GNU_parallel")
704705
declare -r wrapper_programmingide=("android_studio" "sublime_text" "pycharm" "intellij_community" "visualstudiocode" "pypy3" "clion")

data/core/feature_arguments.sh

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,6 @@ checkout_arguments=("checkout")
3030
cheese_arguments=("cheese")
3131
chess_arguments=("gnome_chess" "chess")
3232
chrome_arguments=("chrome" "google_chrome" "googlechrome")
33-
chrome_arguments=("google_chrome")
3433
clean_arguments=("clean")
3534
clementine_arguments=("clementine")
3635
clion_arguments=("clion")
@@ -51,7 +50,6 @@ customizerGUI_arguments=("customizer_gui" "gui")
5150
d_arguments=("d")
5251
dart_arguments=("dart")
5352
dbeaver_arguments=("dbeaver")
54-
dbeaver_arguments=("dbeaver")
5553
dconfEditor_arguments=("dconf_editor" "dconf")
5654
dia_arguments=("dia")
5755
discord_arguments=("discord")

data/features/clone/clone.dat.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11

22
clone_name="Function clone"
3-
clone_description="Function for `git clone $1`"
3+
clone_description="Function for git clone \$1"
44
clone_version="1.0"
55
clone_tags=("gitbashfunctions")
66
clone_systemcategories=("System" "Utility")
Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1,13 @@
1-
Private network search
1+
duckduckgo_name="Duckduckgo"
2+
duckduckgo_description="Duckduckgo opening in Browser"
3+
duckduckgo_version="Google dependent"
4+
duckduckgo_tags=("search" "internet_shortcuts")
5+
duckduckgo_systemcategories=("WebBrowser")
6+
duckduckgo_arguments=("duckduckgo")
7+
8+
duckduckgo_bashfunctions=("silentFunction")
9+
duckduckgo_launcherkeynames=("default")
10+
duckduckgo_default_exec="xdg-open https://duckduckgo.com/"
11+
duckduckgo_description="Opens DuckDuckGo in Chrome"
12+
13+
Lines changed: 1 addition & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1 @@
1-
duckduckgo_name="Duckduckgo"
2-
duckduckgo_description="Duckduckgo opening in Browser"
3-
duckduckgo_version="Google dependent"
4-
duckduckgo_tags=("search" "internet_shortcuts")
5-
duckduckgo_systemcategories=("WebBrowser")
6-
duckduckgo_arguments=("duckduckgo")
7-
8-
duckduckgo_bashfunctions=("silentFunction")
9-
duckduckgo_launcherkeynames=("default")
10-
duckduckgo_default_exec="xdg-open https://duckduckgo.com/"
11-
duckduckgo_description="Opens DuckDuckGo in Chrome"
1+
Private network search

data/features/go/go.dat.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ go_name="go language"
33
go_description="google programming language"
44
go_version="1.17.linux-amd64"
55
go_systemcategories=("Languages")
6-
go_tags=("search" "internet_shortcuts")
6+
go_tags=("search")
77
go_downloadkeys=("bundle")
88
go_bundle_URL="https://golang.org/dl/go1.17.linux-amd64.tar.gz"
99
go_bundle_downloadPath="/usr/local"

data/features/lolcat/lolcat.dat.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11

22
lolcat_name="Function lolcat"
3-
lolcat_description="Same as the command `cat` but outputting the text in rainbow color and concatenate string"
3+
lolcat_description="Same as the command cat but outputting the text in rainbow color and concatenate string"
44
lolcat_version="System dependent"
55
lolcat_tags=("terminal" "system")
66
lolcat_systemcategories=("System" "Utility")

data/features/nedit/nedit.dat.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11

2-
nedit_name="NEdit "Nirvana Text Editor""
2+
nedit_name="NEdit Nirvana Text Editor"
33
nedit_description="Text Editor"
44
nedit_version="System dependent"
55
nedit_tags=("editor" "Customizable" "Scripts" "Powerful")

data/features/templates/templates.dat.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11

22
templates_name="Templates"
3-
templates_description="Different collection of templates for starting code projects: Python3 script (`.py`), Bash script (`.sh`), LaTeX document (`.tex`), C script (`.c`), C header script (`.h`), makefile example (`makefile`) and empty text file (`.txt`)"
3+
templates_description="Different collection of templates for starting code projects: Python3 script (.py), Bash script (.sh), LaTeX document (.tex), C script (.c), C header script (.h), makefile example (makefile) and empty text file (.txt)"
44
templates_version="1.0"
55
templates_tags=("bashfunctions" "terminal")
66
templates_systemcategories=("System" "Utility")

src/core/functions_common.sh

100755100644
Lines changed: 48 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -237,42 +237,60 @@ append_text()
237237
# - Arguments: Reads the tags property of each feature and maps that feature to a wrapper with the name of each tag.
238238
generate_wrappers()
239239
{
240-
declare -Ag wrapper_dict
240+
declare -Ag WRAPPERS_KEYNAMES
241241
for feature_name in "${feature_keynames[@]}"; do
242242
load_feature_properties "${feature_name}"
243+
244+
# Use tags to fill wrappers dictionary
243245
tags_pointer="${feature_name}_tags[@]"
244-
for tag in "${!tags_pointer}"; do
245-
if [[ -v wrapper_dict["${tag}"] ]]; then
246-
wrapper_dict[$tag]+=" ${feature_name}"
246+
for tag in ${!tags_pointer}; do
247+
if [[ -v WRAPPERS_KEYNAMES["${tag}"] ]]; then
248+
WRAPPERS_KEYNAMES[$tag]+=" ${feature_name}"
249+
else
250+
WRAPPERS_KEYNAMES[$tag]="${feature_name}"
251+
fi
252+
done
253+
254+
# Use system categories to fill wrappers dictionary
255+
categories_pointer="${feature_name}_systemcategories[@]"
256+
for category in ${!categories_pointer}; do
257+
if [[ -v WRAPPERS_KEYNAMES["${category}"] ]]; then
258+
WRAPPERS_KEYNAMES[${category}]+=" ${feature_name}"
247259
else
248-
wrapper_dict[$tag]="${feature_name}"
260+
WRAPPERS_KEYNAMES[${category}]="${feature_name}"
249261
fi
250262
done
251263
done
264+
}
252265

253-
for key in $(echo "${!wrapper_dict[@]}" | tr ' ' $'\n' | sort -h); do
254-
echo "Tag: ${key} --- Feature: ${wrapper_dict[$key]}"
266+
267+
# - Description: Prints the list that contains the list of included programs for each wrapper.
268+
# - Permissions: Can be executed indifferently as root or user.
269+
display_wrappers()
270+
{
271+
for key in $(echo "${!WRAPPERS_KEYNAMES[@]}" | tr ' ' $'\n' | sort -h); do
272+
echo "Tag: ${key} --- Feature: ${WRAPPERS_KEYNAMES[$key]}"
255273
done
256274
}
257275

258-
# - Description: Generate the list that contains the list of included programs for each wrapper.
276+
277+
# - Description: Load properties from a feature received in the first argument as a keyname
259278
# - Permissions: Can be executed indifferently as root or user.
260-
# - Argument 1: Keyname of the properties to import
261279
load_feature_properties()
262280
{
263281
# Load metadata of the feature if its .dat file exists
264-
if [ -f "${CUSTOMIZER_PROJECT_FOLDER}/data/features/${CURRENT_INSTALLATION_KEYNAME}/${CURRENT_INSTALLATION_KEYNAME}.dat.sh" ]; then
265-
source "${CUSTOMIZER_PROJECT_FOLDER}/data/features/${CURRENT_INSTALLATION_KEYNAME}/${CURRENT_INSTALLATION_KEYNAME}.dat.sh"
282+
if [ -f "${CUSTOMIZER_PROJECT_FOLDER}/data/features/$1/$1.dat.sh" ]; then
283+
source "${CUSTOMIZER_PROJECT_FOLDER}/data/features/$1/$1.dat.sh"
266284

267285
# If we find the property manual_content_available declared, we should import the function file too
268-
local -r manualContentPointer="${CURRENT_INSTALLATION_KEYNAME}_manualcontentavailable"
286+
local -r manualContentPointer="$1_manualcontentavailable"
269287
if [ -n "${!manualContentPointer}" ]; then
270-
if [ -f "${CUSTOMIZER_PROJECT_FOLDER}/data/features/${CURRENT_INSTALLATION_KEYNAME}/${CURRENT_INSTALLATION_KEYNAME}.func.sh" ]; then
271-
source "${CUSTOMIZER_PROJECT_FOLDER}/data/features/${CURRENT_INSTALLATION_KEYNAME}/${CURRENT_INSTALLATION_KEYNAME}.func.sh"
288+
if [ -f "${CUSTOMIZER_PROJECT_FOLDER}/data/features/$1/$1.func.sh" ]; then
289+
source "${CUSTOMIZER_PROJECT_FOLDER}/data/features/$1/$1.func.sh"
272290
fi
273291
fi
274292
else
275-
output_proxy_executioner "Properties of $1 feature have not been loaded. The file ${CUSTOMIZER_PROJECT_FOLDER}/data/features/${CURRENT_INSTALLATION_KEYNAME}/${CURRENT_INSTALLATION_KEYNAME}.dat.sh does not exist" "ERROR"
293+
output_proxy_executioner "Properties of $1 feature have not been loaded. The file ${CUSTOMIZER_PROJECT_FOLDER}/data/features/$1/$1.dat.sh does not exist" "ERROR"
276294
fi
277295
}
278296

@@ -601,6 +619,12 @@ argument_processing()
601619
exit 0
602620
;;
603621

622+
--show-wrappers)
623+
generate_wrappers
624+
display_wrappers
625+
exit 0
626+
;;
627+
604628
--debug)
605629
customizer_prompt
606630
;;
@@ -664,13 +688,17 @@ argument_processing()
664688
fi
665689

666690
# Indirect expand wrapper variable
667-
local wrapper_key=
668-
wrapper_key="$(echo "${key}" | tr "-" "_" | tr -d "_")"
669-
local set_of_features="wrapper_${wrapper_key}[*]"
670-
if [ -z "${!set_of_features}" ]; then
691+
generate_wrappers # Fill WRAPPERS_KEYNAMES dictionary
692+
local wrapper_key
693+
wrapper_key="$(echo "${key}" | tr "-" "_")"
694+
local set_of_features="${WRAPPERS_KEYNAMES[${wrapper_key}]}"
695+
if [ -z "${set_of_features}" ]; then
696+
# If there are no wrappers corresponding with this key, the last possibility is that the key is actually a
697+
# feature keyname, which we try to add to installation.
671698
add_program "${key}"
672699
else
673-
add_programs ${!set_of_features}
700+
# There is a wrapper corresponding with this key, so we add each program that is in the wrapper.
701+
add_programs ${set_of_features}
674702
fi
675703
;;
676704
esac

0 commit comments

Comments
 (0)