-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmenu.sh
132 lines (107 loc) · 2.94 KB
/
menu.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
#!/bin/bash
# Menu
# r2020-04-28 fr2020-04-28
# by Valerio Capello - http://labs.geody.com/ - License: GPL v3.0
# trap "" 1 2 3 20 # Traps Signals and Interrupts: blocks Ctrl+C , Ctrl+\ , Ctrl+Z , Ctrl+D (use only if the user must be forced to stay into the menu)
# Config
shwmenu=0; # Always show the menu after every operation (1: True, 0: False)
shwmenucls=1; # Clear screen before showing the menu. It will also request to hit a key after every operation (1: True, 0: False)
startcls=1; # Clear the screen at startup (1: True, 0: False)
onekeyc=1; # Single Keypress for menu choice, rather than having to hit Enter (1: True, 0: False)
# xedit=jed ; # Editor of choice
tsproon="\e[0;32m"; # Prompt Text On
tsproof="\e[0m"; # Prompt Text Off
tshilon="\e[0;33m"; # Hilight Text On
tshilof="\e[0m"; # Hilight Text Off
tsalerton="\e[0;31m"; # Alert Text On
tsalertof="\e[0m"; # Alert Text Off
# Menu Operations
# Operation: Hello World
xfx_hello_world() {
echo "Hello World!";
# waitkey ; # echo ;
}
# Operation: Show Date and Time
xfx_show_time() {
date "+%a %d %b %Y %H:%M:%S %Z (UTC%:z)"
}
# Operation: Ring the Bell
xfx_ring_bell() {
# echo "*Bell*";
local TIMES="$1"
if [ "$TIMES" == "" ]; then TIMES=1; fi
if [ "$TIMES" -le 0 ]; then TIMES=0;
else
for ((i=1; i <= $TIMES; i++)); do
# echo -n "$i ";
printf '\7'; sleep 0.2;
done
# echo
fi
}
# App Functions
greetings() {
echo -n "Hello "; echo -ne "$tshilon"; echo -n "$(whoami)"; echo -ne "$tshilof";
if [ "$SSH_CONNECTION" ]; then
echo -n " ("; echo -ne "$tshilon"; echo -n "`echo $SSH_CLIENT | awk '{print $1}'`"; echo -ne "$tshilof)";
fi
echo -n ", ";
echo -n "this is "; echo -ne "$tshilon"; echo -n "$(hostname)"; echo -ne "$tshilof";
# echo -n " ("; echo -ne "$tshilon"; echo -n "$(hostname -i)"; echo -ne "$tshilof)";
echo ".";
}
waitkey() {
read -rs -n 1 -p "Press any key to continue..." wkey
}
# Display Menu (Function)
show_menu() {
if [ $shwmenucls -eq 1 ]; then clear ; fi
greetings
xfx_show_time
echo ;
echo "MENU"
echo ;
echo "1. Hello World!"
echo "2. Show Date and Time"
# echo "C. Clear Screen"
echo "G. Ring the Bell"
echo "M. Show This Menu"
echo "Q. Quit"
}
# Call requested operation
choose_option() {
local choice
echo -ne "$tsproon";
echo -n "Enter choice ";
if [ $shwmenu -eq 0 ]; then echo -n "[M for Menu] "; fi
echo -n ": ";
echo -ne "$tsproof";
if [ $onekeyc -eq 1 ]; then
read -r -n 1 -p "" choice # Key press
echo ;
else
read -r -p "" choice # Type choice and hit Enter
fi
local wkeyi=1;
case $choice in
"1") xfx_hello_world ;;
"2") xfx_show_time ;;
"c"|"C") clear ;;
"g"|"G") xfx_ring_bell "1" ;;
"m"|"M"|"h"|"H") show_menu; wkeyi=0 ;;
"q"|"Q"|"x"|"X") exit 0 ;;
*) echo -e "${tsalerton}Invalid option.${tsalertof}"
esac
if [ $shwmenu -eq 1 ] && [ $shwmenucls -eq 1 ] && [ $wkeyi -eq 1 ]; then
waitkey ; # echo ; # sleep 2 ;
fi
}
# Main
if [ $startcls -eq 1 ]; then clear ; fi
if [ $shwmenu -eq 0 ]; then show_menu ; fi
while true
do
echo ;
if [ $shwmenu -eq 1 ]; then show_menu ; fi
choose_option
done