blob: e3854bb4e686d708f1380e8619840fa973ebed51 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
|
#!/bin/bash
# ################################################################ #
# Frontend to smenu to display a nice menu #
# #
# FLAGS: -i (optional) add some help in the title #
# #
# ARGS: $1 (required) must contain a string which will become #
# the menu title #
# $2... (optional) adds more options passed to smenu #
# #
# RC: 0 OK #
# 1 KO #
# ################################################################ #
# ============== #
# usage function #
# ============== #
function usage
{
echo "menu.sh [-i] title [smenu options]"
exit 1
}
declare integer INFO=0
# Option processing
# """""""""""""""""
while getopts ih OPT 2>/dev/null
do
case ${OPT} in
i) INFO=1
;;
h|*) usage
exit 1
;;
esac
done
shift $((${OPTIND} - 1))
# Menu title generation
# """""""""""""""""""""
if [[ $1 ]]; then
MESSAGE="$1"
(( INFO )) && MESSAGE+=$'\n'"[ q=quit arrows=move ?=help ]"
TITLE="-m"
TITLE+=$MESSAGE$'\n'
shift
else
TITLE="-m "
fi
# Menu display
# """"""""""""
REP=$(../../smenu "$TITLE" \
-s /Exit \
-q -d -M -n 30 -c -w \
-N "Exit menu" e:r \
-a da:3,b \
-e '^#' -E '/(^#)+(.*)$/ \2/v' \
-1 'Exit' 2,r \
-I '/([^ ]+) (.*)/\2/v' \
$1 \
|| echo Abort)
read KEY DUMMY <<< $REP
# Action processing
# """""""""""""""""
case $KEY in
Abort)
echo ABORT
;;
""|Quit)
echo QUIT
;;
*)
echo $KEY
;;
esac
# Normal exit
# """""""""""
exit 0
|