summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorpgen <p.gen.progs@gmail.com>2019-03-29 19:56:22 +0100
committerpgen <p.gen.progs@gmail.com>2019-03-30 11:39:03 +0100
commitc264b6de8a6cd615bc32f056cc11ff4c578af580 (patch)
tree728aff038b97f8efbfb0b0ef4eac15cdc5fa208c
parent21c53c7920633c4f6a848c2f418b5ff4cf3fd52a (diff)
Improve examples scripts
Use the distributed smenu binary to run the examples.
-rw-r--r--examples/lvm_menu/lvm_menu.sh16
-rw-r--r--examples/lvm_menu/menu.sh10
-rw-r--r--examples/simple_menu/simple_menu.sh12
-rw-r--r--examples/yesno/yesno.sh18
4 files changed, 45 insertions, 11 deletions
diff --git a/examples/lvm_menu/lvm_menu.sh b/examples/lvm_menu/lvm_menu.sh
index 3f5c076..791237e 100644
--- a/examples/lvm_menu/lvm_menu.sh
+++ b/examples/lvm_menu/lvm_menu.sh
@@ -1,5 +1,19 @@
#!/usr/bin/env bash
+# ==================== #
+# Fatal error function #
+# ==================== #
+function error
+{
+ echo $* >&2
+ exit 1
+}
+
+# Check for the presence of smenu
+# """""""""""""""""""""""""""""""
+SMENU=$(which smenu 2>/dev/null)
+[[ -x "$SMENU" ]] || error "smenu is not in the PATH or not executable."
+
MENU+="\
'Create' 'Delete' 'Extend' 'Shrink'
'VGC VG' 'VGD VG' 'VGE VG' 'VGS VG'
@@ -19,7 +33,7 @@ do
echo
MESSAGE="LVM management"
- read REP <<< $(echo "$MENU" | ./menu.sh -i "$MESSAGE" "-Re1")
+ read REP <<< $(echo "$MENU" | ./menu.sh -p $SMENU -i "$MESSAGE" "-Re1")
case $REP in
ABORT) exit 1 ;;
diff --git a/examples/lvm_menu/menu.sh b/examples/lvm_menu/menu.sh
index bfada7e..e8a989e 100644
--- a/examples/lvm_menu/menu.sh
+++ b/examples/lvm_menu/menu.sh
@@ -3,7 +3,8 @@
# ################################################################ #
# Frontend to smenu to display a nice menu #
# #
-# FLAGS: -i (optional) add some help in the title #
+# FLAGS: -p The path of the smenu program #
+# -i (optional) add some help in the title #
# #
# ARGS: $1 (required) must contain a string which will become #
# the menu title #
@@ -26,9 +27,12 @@ declare integer INFO=0
# Option processing
# """""""""""""""""
-while getopts ih OPT 2>/dev/null
+while getopts p:ih OPT 2>/dev/null
do
case ${OPT} in
+ p) SMENU=${OPTARG}
+ ;;
+
i) INFO=1
;;
@@ -53,7 +57,7 @@ fi
# Menu display
# """"""""""""
-REP=$(../../smenu "$TITLE" \
+REP=$($SMENU "$TITLE" \
-s /Exit \
-q -d -M -n 30 -c -w \
-U "Exit menu" \
diff --git a/examples/simple_menu/simple_menu.sh b/examples/simple_menu/simple_menu.sh
index 1d8dd7d..5752f0e 100644
--- a/examples/simple_menu/simple_menu.sh
+++ b/examples/simple_menu/simple_menu.sh
@@ -14,7 +14,8 @@ typeset -A CENTERING_ARRAY
typeset -A TITLE_ARRAY
typeset -A ERASE_ARRAY
-SEL= # The selection
+SEL= # The selection
+SMENU= # The smenu path will be stored here
# ============================ #
# Usage function, always fails #
@@ -140,7 +141,7 @@ function process_menu
# Display the menu and get the selection
# """"""""""""""""""""""""""""""""""""""
- SEL=$(echo "$MENU" | ../../smenu \
+ SEL=$(echo "$MENU" | $SMENU \
$CENTERING \
$ERASE \
-N \
@@ -155,9 +156,10 @@ function process_menu
SEL=${SEL%% *}
}
-# Check for the presence of ../../smenu
-# """""""""""""""""""""""""""""""""""""
-[[ -x ../../smenu ]] || error "smenu is not there, please build it."
+# Check for the presence of smenu
+# """""""""""""""""""""""""""""""
+SMENU=$(which smenu 2>/dev/null)
+[[ -x "$SMENU" ]] || error "smenu is not in the PATH or not executable."
# Initialize the menu stack with the argument
# """""""""""""""""""""""""""""""""""""""""""
diff --git a/examples/yesno/yesno.sh b/examples/yesno/yesno.sh
index d0d9b47..e7efc2e 100644
--- a/examples/yesno/yesno.sh
+++ b/examples/yesno/yesno.sh
@@ -1,8 +1,22 @@
#!/usr/bin/env bash
+# ==================== #
+# Fatal error function #
+# ==================== #
+function error
+{
+ echo $* >&2
+ exit 1
+}
+
+# Check for the presence of smenu
+# """""""""""""""""""""""""""""""
+SMENU=$(which smenu 2>/dev/null)
+[[ -x "$SMENU" ]] || error "smenu is not in the PATH or not executable."
+
RES=$(
- ../../smenu -2 ^Y -1 ^N -3 ^C -s /^N -x cur 10 \
- -m "Please confirm your choice:" \
+ $SMENU -2 ^Y -1 ^N -3 ^C -s /^N -x cur 10 \
+ -m "Please confirm your choice:" \
<<< "YES NO CANCEL"
)