provide a bash properties editor to edit project_params

Signed-off-by: philippe lhardy <philippe@pavilionartlogiciel>
This commit is contained in:
philippe lhardy
2015-02-17 22:57:34 +01:00
parent 2a8f80154f
commit 894e5c7970

89
doit.sh
View File

@@ -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" possible_console_gui="whiptail dialog"
@@ -51,7 +135,7 @@ action=initial
while [[ $action != quit ]] while [[ $action != quit ]]
do 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 ]] if [[ $action == run ]]
then then
@@ -83,5 +167,8 @@ do
elif [[ $action == readme ]] elif [[ $action == readme ]]
then then
$DIALOG --textbox README 20 80 $DIALOG --textbox README 20 80
elif [[ $action == properties ]]
then
edit_properties project_params
fi fi
done done