-
Notifications
You must be signed in to change notification settings - Fork 0
/
Linux.sh
102 lines (86 loc) · 2.32 KB
/
Linux.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
#!/bin/bash
file=a.txt
add_entry() {
entry=$(whiptail --fb --inputbox "Add an entry" 10 100 --cancel-button "Cancel" --title "Adding entry" 3>&1 1>&2 2>&3)
esc=$?
if [ $esc = 0 ]; then
if [ -z "$entry" ]; then
whiptail --fb --msgbox "Sorry, you have to type something." 10 50
else
counter="$(echo $entry | xargs)"
if [ -z "$counter" ]; then
whiptail --fb --msgbox "no entry added" 10 50
return 0
fi
esc=$?
echo $entry >> $file
whiptail --fb --msgbox "Success." 10 50
fi
fi
return 0
}
search() {
Sentry=$(whiptail --fb --inputbox "Type what you want to find" 10 50 --title "SEARCH" --nocancel 3>&1 1>&2 2>&3)
esc=$?
if [ $esc = 0 ]; then
if [ -z "$Sentry" ]; then
whiptail --msgbox "Sorry, you have to type something." 10 50
else
if [[ -s $file ]]; then
s=`cat a.txt | grep "$Sentry"`
if [[ $s == $Sentry ]]; then
whiptail --fb --title "Result" --msgbox "Avaliable: $s" --scrolltext 10 50
else
whiptail --fb --title "Result" --msgbox "Could not find it" --scrolltext 10 50
fi
else
whiptail --fb --title "Result" --msgbox "No entry added yet." --scrolltext 10 50
fi
fi
fi
}
listAll() {
if [[ -s $file ]]; then
whiptail --title Listing --textbox a.txt --scrolltext 10 50
else
whiptail --fb --title "Result" --msgbox "No entry added yet." --scrolltext 10 50
fi
}
delete() {
Rentry=$(whiptail --fb --inputbox "Type what you want to delete" 10 50 --title "Delete" 3>&1 1>&2 2>&3)
esc=$?
if [[ $esc == 0 ]]; then
del=$Rentry
output=`cat a.txt | grep "$del"`
if [[ $output == $del ]]; then
sed -i "/^$del/d" a.txt
whiptail --fb --title "Success" --msgbox "Successfully deleted" 10 50
else
whiptail --fb --title "Unsuccessful" --msgbox "Could not find it" 10 50
fi
fi
}
quit() {
if (whiptail --fb --title "Exit" --yesno "Are you sure?" --yes-button "I'm sure" --no-button "Cancel" 10 50 ); then
exit
fi
}
while :; do
secim=$(whiptail --fb --title "Menu" --menu "Choose what you want to do..." 15 45 5 --nocancel \
"1)" "Add Entry" \
"2)" "List all" \
"3)" "Search an entry" \
"4)" "Delete an entry" \
"5)" "Exit" 3>&2 2>&1 1>&3)
case "$secim" in
"1)") add_entry ;;
"2)") listAll ;;
"3)") search ;;
"4)") delete ;;
"5)") quit ;;
*)
if [ "$?" == "1" ]; then
quit
fi
esac
done