-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmenu2.sh
executable file
·194 lines (175 loc) · 5.86 KB
/
menu2.sh
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
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
#!/bin/bash
#######################################################################
# Title : test_dialog
# Author : Bernd Holzhauer {[email protected]}
# Date : 2007-11-02
# Requires : dialog
# Category : Shell menu tools
#######################################################################
# Description
# DIALOG test & demo
# Sample Script without functionality - just to test and demonstrate
# the usage of the dialog features
# Note:
# - it draws a small main menu to try different dialog options
#######################################################################
_temp="/tmp/answer.$$"
PN=`basename "$0"`
VER='0.31'
dialog 2>$_temp
DVER=`cat $_temp | head -1`
### gauge demo ###
gauge() {
{ for I in $(seq 1 100) ; do
echo $I
sleep 0.01
done
echo 100; } | dialog --backtitle "Dialog - Progress sample" \
--gauge "Progress" 6 60 0
}
### File or Directory selection menu with dialog
file_menu() {
fileroot=$HOME
IFS_BAK=$IFS
IFS=$'\n' # wegen Filenamen mit Blanks
array=( $(ls $fileroot) )
n=0
for item in ${array[@]}
do
menuitems="$menuitems $n ${item// /_}" # subst. Blanks with "_"
let n+=1
done
IFS=$IFS_BAK
dialog --backtitle "Dialog - Sample menu with variable items" \
--title "Select a file" --menu \
"Choose one of the menu points" 16 40 8 $menuitems 2> $_temp
if [ $? -eq 0 ]; then
item=`cat $_temp`
selection=${array[$(cat $_temp)]}
dialog --msgbox "You choose:\nNo. $item --> $selection" 6 42
fi
}
### File Select sample
file_select() {
dialog --backtitle "Dialog - fselect sample"\
--begin 3 10 --title " use [blank] key to select "\
--fselect "$HOME/" 10 60 2>$_temp
result=`cat $_temp`
dialog --msgbox "\nYou selected:\n$result" 9 52
}
### create Today's calendar ###
calendar() {
today=$(echo $(date +%m) $(date +%d) $(date +%y))
echo "heute=$today"
dialog --backtitle "Dialog - Calendar sample"
dialog --calendar "choose a date" 13 25
datum=$(cat $_temp)
dialog --title " $today Date selected " --msgbox "\nYour date: $datum" 20 30
}
### Check List - multi select sample ###
checklist() {
dialog --backtitle "Dialog - CheckList (multi select) sample" \
--checklist "tag item(s) to choose" 15 50 8 \
01 "first item to select" off\
02 "second item - on by default" on\
03 "third item" off\
04 "more items ..." off 2>$_temp
result=`cat $_temp`
dialog --title " Item(s) selected " --msgbox "\nYou choose item(s): $result" 6 44
}
### Radio List - single select sample ###
radiolist() {
dialog --backtitle "Dialog - RadioList (single select) sample" \
--radiolist "tag item to choose" 15 50 8 \
01 "first item to select" off\
02 "second item - on by default" on\
03 "third item" off\
04 "more items ..." off 2>$_temp
result=`cat $_temp`
dialog --title " Item(s) selected " --msgbox "\nYou choose item: $result" 6 44
}
### Input Box sample
inputbox() {
dialog --backtitle "Dialog - InputBox sample"\
--inputbox "Enter a line, please" 8 52 2>$_temp
result=`cat $_temp`
dialog --msgbox "\nYou entered:\n$result" 9 52
}
### Message Box sample - show versions
version() {
dialog --backtitle "Dialog - MessageBox sample" \
--msgbox "$PN - Version $VER\na Linux dialog Tutorial\n\nusing:\n$DVER" 9 52
}
### Text Box sample - show file test.txt
textbox() {
filename="test.txt"
if [ -e $filename ]; then
dialog --backtitle "Dialog - TextBox sample - use [up] [down] to scroll"\
--begin 3 5 --title " viewing File: $filename "\
--textbox $filename 20 70
else
dialog --msgbox "*** ERROR ***\n$filename does not exist" 6 42
fi
}
### Form Sample ###
formbox () {
dialog --backtitle "Dialog - Form sample" \
--form " Form Test - use [up] [down] to select input field " 21 70 18 \
"name" 2 4 "" 2 15 20 0\
"surname" 4 4 "" 4 15 20 0\
"city" 6 4 "" 6 15 20 0\
"county" 8 4 "Germany" 8 15 "-20" 0\
2>$_temp
if [ ${?} -ne 0 ]; then return; fi
result=`cat $_temp`
echo "Result=$result"
dialog --title "Items are separated by \\n" --cr-wrap \
--msgbox "\nYou entered:\n$result" 12 52
}
### Text Box sample - show file test.txt
tailbox() {
dialog --backtitle "Dialog - TailBox sample"\
--begin 3 5 --title " viewing File: /var/log/messages "\
--tailbox /var/log/messages 18 70
}
### create main menu using dialog
main_menu() {
dialog --backtitle "Dialog - Linux Shell Tutorial" --title " Main Menu - V. $VER "\
--cancel-label "Quit" \
--menu "Move using [UP] [DOWN], [Enter] to select" 17 60 10\
Calendar "Show today's calendar "\
Editor "Start vi editor with test.txt"\
File "Show Dirctory & File selector"\
Form "Show a form"\
Home_Menu "Show files in \$HOME for selection"\
Input "Show Box for typing a line"\
Gauge "Progress bar"\
Multi "Multi select list"\
Radio "Single select list"\
Show "Show file test.txt"\
Tail "Watch /var/log/messages"\
Version "Show program version info"\
Quit "Exit demo program" 2>$_temp
opt=${?}
if [ $opt != 0 ]; then rm $_temp; exit; fi
menuitem=`cat $_temp`
echo "menu=$menuitem"
case $menuitem in
Gauge) gauge;;
File) file_select;;
Home_Menu) file_menu;;
Input) inputbox;;
Calendar) calendar;;
Editor) vi test.txt;;
Multi) checklist;;
Radio) radiolist;;
Show) textbox;;
Tail) tailbox;;
Version) version;;
Form) formbox;;
Quit) rm $_temp; exit;;
esac
}
while true; do
main_menu
done