Merge pull request #87 into master

f0561d1 client: lib_gen: superscript: append subprofile before generating (Aaron Fiore)
This commit was merged in pull request #87.
This commit is contained in:
2024-07-16 17:56:46 -07:00

View File

@@ -461,40 +461,31 @@ function lib_gen::__gen_shell()
local _file="$global_shell_file"
if [ -f "$_file" ]; then
# Backup
lib_utils::print_custom " \e[32m│ │ └─\e[34m Shell superscript found, backup before continuing? [Y/n] \e[0m"
# Append subprofile source to existing file
lib_utils::print_custom " \e[32m│ │ └─\e[34m Shell superscript found, append new subprofile to existing file? [Y/n] \e[0m"
read -p "" _read
local _confirm="${_read:-y}"
if [[ "$_confirm" == [yY] ]]; then
grep "$_source" "$_file" >&/dev/null || sed -i "$(wc -l <$_file)i\\$_source\\" "$_file"
fi
# Or generate new file
lib_utils::print_custom " \e[32m│ │ └─\e[34m Backup existing superscript and generate a new one? [N/y] \e[0m"
read -p "" _read
local _confirm="${_read:-n}"
if [[ "$_confirm" == [yY] ]]; then
# Backup
local -r _backup=("cp" "-a" "$_file" "${_file}_${global_suffix}")
lib_utils::print_debug "${_backup[@]}"
"${_backup[@]}" || lib_utils::die_fatal
fi
lib_utils::print_custom " \e[32m│ │ └─\e[34m Overwrite existing file? [Y/n] \e[0m"
read -p "" _read
local _confirm="${_read:-y}"
if [[ "$_confirm" == [yY] ]]; then
# Overwrite existing file
# Write
lib_gen::__gen_shell_write
else
# Append subprofile source to existing file
lib_utils::print_custom " \e[32m│ │ └─\e[34m Append to existing file? [Y/n] \e[0m"
read -p "" _read
local _confirm="${_read:-y}"
if [[ "$_confirm" == [yY] ]]; then
grep "$_source" "$_file" >&/dev/null || sed -i "$(wc -l <$_file)i\\$_source\\" "$_file"
fi
fi
local _print_custom=" \e[32m│ │ └─\e[34m Edit (new) superscript now? [Y/n] \e[0m"
else
# Create new file
# Generate new default file
lib_gen::__gen_shell_write
local _print_custom=" \e[32m│ │ └─\e[34m Edit (new) superscript now? [Y/n] \e[0m"
fi
lib_utils::print_custom "$_print_custom"
read -p "" _read
local _confirm="${_read:-y}"