diff --git a/setup.sh b/setup.sh index 9b273bfb5c8c0c2806fe3470df6fee5da3fe89d6..df6ffa80941991848dea4c4ae848e8991a7b56ac 100755 --- a/setup.sh +++ b/setup.sh @@ -70,8 +70,23 @@ function manage_plugins() { SAVEIFS=$IFS IFS=$'\n' + preset_list=($(git config -f Plugins/unrealplugins/presets.config --name-only --get-regexp ".*.name")) plugin_list=($(git config -f Plugins/unrealplugins/plugins.config --name-only --get-regexp ".*.name")) - IFS=$SAVEIFS + IFS=$SAVEIFS + + declare -a preset_ids + declare -a preset_descriptions + declare -a presets + + for i in ${!preset_list[@]} + do + preset_id=${preset_list[$i]%.name} + preset_ids+=("$preset_id") + preset_name=$(git config -f Plugins/unrealplugins/presets.config --get "$preset_id.name") + presets+=("${preset_name}") + preset_description=$(git config -f Plugins/unrealplugins/presets.config --get "$preset_id.description") + preset_descriptions+=("${preset_description}") + done declare -a plugin_ids declare -a plugins @@ -88,13 +103,7 @@ function manage_plugins() { if [ "$1" == "initial_setup" ] then - branch=($(git config -f Plugins/unrealplugins/plugins.config --get "$plugin_id.default-branch")) - if [ $? == 0 ] - then - plugin_branches+=("$branch") - else - plugin_branches+=("") - fi + plugin_branches+=("") else path=$(git config -f .gitmodules --get "submodule.Plugins/${plugin_id}.path") if [ $? == 0 ] @@ -112,6 +121,89 @@ function manage_plugins() { fi done + if [ "$1" == "initial_setup" ] + then + selection=0 + exit=false + cancel=false + num_presets_minus_one=${#presets[@]} + let num_presets_minus_one-=1 + + while [ $exit == "false" ] + do + clear + + echo "Select plugin preset:" + echo "" + + for i in ${!presets[@]} + do + if [ $i == $selection ] + then + printf "\e[7m" + fi + + echo " ${presets[$i]}" + + if [ $i == $selection ] + then + printf "\e[0m" + fi + done + + echo "" + echo "${preset[$selection]}" + echo "${preset_descriptions[$selection]}" + + echo "" + echo "[Arrow Up/Down] Select preset" + echo "[Enter] Continue" + echo "[Esc] Skip preset selection" + + SAVEIFS=$IFS + IFS='' + escape_char=$(printf "\033") + escape=false + read -rsn1 mode # get 1 character + if [[ $mode == $escape_char ]]; then + escape=true + read -rsn2 mode # read 2 more chars + fi + IFS=$SAVEIFS + case $mode in + "") if [ "$escape" == true ]; then cancel=true; fi; exit=true ;; + "[D") previous_branch $selection ;; + "[C") next_branch $selection ;; + "[A") if [ "$selection" -gt "0" ]; then let selection-=1; fi ;; + "[B") if [ "$selection" -lt "$num_presets_minus_one" ]; then let selection+=1; fi ;; + *) >&2 ;; + esac + + done + + # Set the appropriate plugin branches + if [ "$cancel" != true ] + then + SAVEIFS=$IFS + IFS=$'\n' + preset_plugins=($(git config -f Plugins/unrealplugins/presets.config --name-only --get-regexp "${preset_ids[$selection]}\.plugins\..*")) + IFS=$SAVEIFS + + for plugin in ${preset_plugins[@]} + do + plugin_id=${plugin#"${preset_ids[$selection]}.plugins."} + for i in ${!plugins[@]} + do + if [ $plugin_id == ${plugin_ids[$i]} ] + then + branch=$(git config -f Plugins/unrealplugins/presets.config --get "$plugin") + plugin_branches[$i]=$branch + fi + done + done + fi + fi + function next_branch() { case ${plugin_branches[$1]} in "") plugin_branches[$1]="master" ;;