-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathrun.sh
60 lines (46 loc) · 1006 Bytes
/
run.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
scripts_count=${#scripts[@]}
display_scripts () {
echo "Scripts: "
for i in ${!scripts[@]}; do
echo " $((i+1))) ${scripts[$i]}"
done
echo
echo " 0) quit"
echo
}
read -p "Target file (default=./.bashrc): " file
if [ -z $file ];
then
file="./.bashrc"
fi
display_scripts
while true; do
# Ask for input
echo -n "Select: "
read selected
# Check input is numeric
re='^[0-9]+$'
if ! [[ $selected =~ $re ]] ; then
echo "error: Not a number" >&2
selected=-1
continue
fi
# Check input is in bounds
if [ $selected -gt $scripts_count ]; then
echo "error: Input value too high"
selected=-1
continue
fi
# Handle exit option (value 0)
if [ $selected -eq 0 ]; then
source $file
echo "Remember to 'source $file'"
break
fi
echo "-----"
index=$((selected - 1))
eval "run_${scripts[$index]}"
echo "${scripts[$index]} saved to $file"
echo "-----"
display_scripts
done