-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmenu.sh
82 lines (53 loc) · 1.49 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
#!/usr/bin/env bash
param=$1
last_cmd=0
inst_data="some info for the top left"
title="Select Action"
function main(){
menu_options=()
cat $0 | grep -A1 '^#func:' | grep -v '^-' | sed 's/(){//' | sed 's/^function //' | sed 's/^#func://' | while read l1; do read l2; echo "$l2 $l1"; done > menu.items.txt
while read -r number text; do
menu_options+=( ${number//\"} "${text//\"}" )
done < menu.items.txt
export inp=$(whiptail --backtitle "`date` $inst_data" --title "$title" --cancel-button "Quit" --notags --default-item $last_cmd --menu "Choose an option" 25 78 16 "${menu_options[@]}" 3>&2 2>&1 1>&3-)
[ ! $inp ] && exit
last_cmd=$inp
$inp
}
#func: "run top"
function run_top(){
top
}
#func: "hellow world"
function hellow_world(){
echo "hello world" | less
}
#func: "hellow world 2"
function hellow_world2(){
echo "hello world 2"
another_service_function
}
function another_service_function(){
echo "this is a function not in the menu"
}
#func: "du in paralle"
function paralle_process(){
paralle_process_job | sort -k1 | less
}
function paralle_process_job(){
ftemplate=/tmp/updater_s3_flie_times
rm $ftemplate.*
for k in var etc usr;
do
du -hs "/$k/" > $ftemplate.$k &
echo $! >> $ftemplate.pids
done
while kill -0 $(cat $ftemplate.pids) 2> /dev/null; do sleep .1; done;
rm $ftemplate.pids
cat $ftemplate.*
}
#func: "quit"
function quit(){
exit 0
}
while :; do main;sleep 0.2; done