-
Notifications
You must be signed in to change notification settings - Fork 0
/
inventory.sh
100 lines (93 loc) · 2.18 KB
/
inventory.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
#!/bin/bash
# Create Environment Variable
export filename="games.txt"
showChoices(){
clear
echo "Choose the following options"
echo "'Add' in a new game"
echo "'Back' to the menu"
echo "'Look' at the names of your current games"
echo "'View' your text file (Will open with the 'less' command)"
echo "'Clear' your text file"
}
checkFile(){
if [ -s $filename ]; then
return 0
else
return 1
fi
}
clearFile(){
clear
echo "WARNING!!!!!"
echo "THIS WILL TOTALLY ERASE EVERYTHING THAT IS IN YOUR FILE!"
read -p "ARE YOU SURE YOU WANT TO PROCEED? (y/n): " warn
if [ $warn == "Y" ] || [ $warn == "y" ]; then
echo "Clearing file"
> $filename
echo "File cleared"
elif [ $warn == "N" ] || [ $warn == "n" ]; then
echo "Aborting"
else
echo "Error"
fi
read -p "Press Enter to go back to the menu" blank
}
viewNames(){
clear
echo "Your current list:"
grep -F "Video Game: " $filename | cut -f 2- -d : | sort
read -p "Press Enter to go back to the menu" blank
}
displayError(){
clear
echo "$filename does not exist or is empty."
read -p "Press Enter to go back to the menu" blank
}
while :
do
showChoices
echo ""
read -p "Enter your choice (W/O Quotations, Case sensitive): " ans
case $ans in
"Add")
if checkFile; then
source ./name.sh
else
touch $filename
source ./name.sh
fi
break
;;
"Back")
# Go back to start script
source ./start.sh
break
;;
"Look")
if checkFile; then
viewNames
else
displayError
fi
;;
"View")
if checkFile; then
less $filename
else
displayError
fi
;;
"Clear")
if checkFile; then
clearFile
else
displayError
fi
;;
*)
echo "Invalid choice"
sleep 1
;;
esac
done