From 894e5c79708ea16d4a57fa0334622e32ab83876f Mon Sep 17 00:00:00 2001 From: philippe lhardy Date: Tue, 17 Feb 2015 22:57:34 +0100 Subject: [PATCH] provide a bash properties editor to edit project_params Signed-off-by: philippe lhardy --- doit.sh | 89 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 88 insertions(+), 1 deletion(-) diff --git a/doit.sh b/doit.sh index a3502e3..61f5ce5 100755 --- a/doit.sh +++ b/doit.sh @@ -29,6 +29,90 @@ do_code() } +edit_properties() +{ + local property_file=$1 + if [[ -f $property_file ]] + then + modified=0 + s=() + properties=() + values=() + { + while read codeline + do + if [[ $codeline =~ (^[a-zA-Z_]*)=(.*) ]] + then + property=${BASH_REMATCH[1]} + value=${BASH_REMATCH[2]} + s+=("$property" "$value") + properties+=("$property") + values+=("$value") + fi + done + s+=(exit "Exit") + } < $property_file + + while true + do + property=$($DIALOG --menu "Edit '$property_file'" 20 100 10 ${s[@]} 3>&1 1>&2 2>&3) + if [[ $? = 0 ]] + then + if [[ -n $property ]] + then + if [[ $property == exit ]] + then + return 1 + elif [[ $property == save ]] + then + for (( i=0; i<${prop_len}; i++ )); + do + echo "${properties[$i]}=${values[$i]}" + done >$property_file + return 0 + fi + prop_len="${#properties[@]}" + for (( i=0; i<${prop_len}; i++ )); + do + if [[ ${properties[$i]} == $property ]] + then + init_value=${values[$i]} + fi + done + value=$($DIALOG --inputbox "Enter $property value" 10 80 "$init_value" 3>&1 1>&2 2>&3) + if [[ $? = 0 ]] + then + prop_len="${#properties[@]}" + s=() + if [[ "$value" != "$init_value" ]] + then + modified=$(( modified + 1 )) + fi + for (( i=0; i<${prop_len}; i++ )); + do + if [[ ${properties[$i]} == $property ]] + then + values[$i]=$value + fi + s+=("${properties[$i]}" "${values[$i]}") + echo "${properties[$i]}=${values[$i]}" + done + s+=(exit "Exit") + if [[ $modified != 0 ]] + then + s+=(save "Save") + fi + fi + fi + else + return 2 + fi + done + else + echo "[ERROR] property_file '$propertyfile' not found" >&2 + fi + +} possible_console_gui="whiptail dialog" @@ -51,7 +135,7 @@ action=initial while [[ $action != quit ]] do - action=$($DIALOG --menu "Ultra Light IDE" 20 80 8 run "Run it" clean "Clean All" ant "Ant build" test "Test it" readme "Read me" code "Code" codebg "Code in background" deb "Debian package" quit "Quit" 3>&1 1>&2 2>&3) + action=$($DIALOG --menu "Ultra Light IDE" 20 80 12 run "Run it" clean "Clean All" ant "Ant build" test "Test it" readme "Read me" code "Code" codebg "Code in background" deb "Debian package" properties "Edit Properties" quit "Quit" 3>&1 1>&2 2>&3) if [[ $action == run ]] then @@ -83,5 +167,8 @@ do elif [[ $action == readme ]] then $DIALOG --textbox README 20 80 + elif [[ $action == properties ]] + then + edit_properties project_params fi done