-
Notifications
You must be signed in to change notification settings - Fork 1
/
portal.sh
executable file
·151 lines (138 loc) · 4.14 KB
/
portal.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
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
#!/bin/bash
arg1="$(tr "[A-Z]" "[a-z]" <<< "$1")"
function portal_help {
echo "Portal is an application that lets you easily go back to different directories in style."
echo "Ussage:"
echo " portal to PORTAL_ALIAS/OPTIONAL_SUB-DIRECTORY | Is used to portal to a specific portal."
echo " portal -m/--make PORTAL_ALIAS | Is used to make a portal at that the current directory."
echo " portal -o/--overwrite | Is used to overwrite an existing portal."
echo " portal -r/--remove PORTAL_ALIAS | Is used to remove a portal."
echo " portal -l/--list | is used to list all portals."
echo " portal -c OPTIONAL_PARAMETER | If no parameter is given, it will list the content of the configuration file."
echo " else it will toggle the parameter in the configuration file."
echo " portal -h/--help | Is used to echo this message."
echo "---conifguration file parameters---"
echo " flavor_messages : If set to true, the flavor messages will be shown."
}
function make_portal {
python /bin/portal_bin/portalCONFIG.py "-r" "flavor_messages"
if [ $? -eq 0 ]; then
echo "Hacking space time..."
fi
if [ -z "$1" ]; then
python /bin/portal_bin/portalCONFIG.py "-r" "flavor_messages"
if [ $? -eq 0 ]; then
echo "Failed to hack space time: missing arguments."
else
echo "Failed to create portal: missing arguments."
fi
else
python /bin/portal_bin/portalDB.py "-E" "$1"
if [ $? -eq 1 ]; then
echo "Portal exists already please use -o instead of -m to overwrite it."
else
python /bin/portal_bin/portalDB.py "-W" "$1" "$(pwd)"
fi
fi
}
function overwrite_portal {
python /bin/portal_bin/portalCONFIG.py "-r" "flavor_messages"
if [ $? -eq 0 ]; then
echo "Hacking space time..."
fi
if [ -z "$1" ]; then
python /bin/portal_bin/portalCONFIG.py "-r" "flavor_messages"
if [ $? -eq 0 ]; then
echo "Failed to hack space time: missing arguments."
else
echo "Failed to overwrite portal: missing arguments."
fi
else
python /bin/portal_bin/portalDB.py "-E" "$1"
if [ $? -eq 1 ]; then
python /bin/portal_bin/portalDB.py "-W" "$1" "$(pwd)"
else
echo "Portal does not exist please use -m instead of -o to make it."
fi
fi
}
function remove_portal {
python /bin/portal_bin/portalCONFIG.py "-r" "flavor_messages"
if [ $? -eq 0 ]; then
echo "Hacking space time..."
fi
if [ -z "$1" ]; then
python /bin/portal_bin/portalCONFIG.py "-r" "flavor_messages"
if [ $? -eq 0 ]; then
echo "Failed to hack space time: missing arguments."
else
echo "Failed to remove portal: missing arguments."
fi
else
python /bin/portal_bin/portalDB.py "-E" "$1"
if [ $? -eq 1 ]; then
python /bin/portal_bin/portalDB.py "-D" "$1"
else
echo "Portal does not exist."
fi
fi
}
function config_portal {
if [ -z "$1" ]; then
python /bin/portal_bin/portalCONFIG.py "-r"
else
python /bin/portal_bin/portalCONFIG.py "-e" "$1"
if [ $? -eq 0 ]; then
python /bin/portal_bin/portalCONFIG.py "$1"
else
echo "Failed to set parameter, parameter invalid."
fi
fi
}
if [ "$arg1" = "-m" ]; then
make_portal "$2"
elif [ "$arg1" = "--make" ]; then
make_portal "$2"
elif [ "$arg1" = "-o" ]; then
overwrite_portal "$2"
elif [ "$arg1" = "-overwrite" ]; then
overwrite_portal "$2"
elif [ "$arg1" = "-r" ]; then
remove_portal "$2"
elif [ "$arg1" = "--remove" ]; then
remove_portal "$2"
elif [ "$arg1" = "to" ]; then
if [ -z "$2" ]; then
echo "Failed to portal: missing arguments."
else
python /bin/portal_bin/portalCONFIG.py "-r" "flavor_messages"
if [ $? -eq 0 ]; then
echo "Entering portal..."
fi
pythonOut=$(python /bin/portal_bin/portalDB.py -R $2)
if [ $? -eq 1 ]; then
echo "Portal $2 does not exist."
else
python /bin/portal_bin/portalDB.py "-R" "$2"
if [ $? -eq 2 ]; then
echo "Directory after portal $2 does not exist."
else
cd ${pythonOut}
fi
fi
fi
elif [ "$arg1" = "-c" ]; then
config_portal "$2"
elif [ "$arg1" = "--config" ]; then
config_portal "$2"
elif [ "$arg1" = "-l" ]; then
python /bin/portal_bin/portalDB.py "-L"
elif [ "$arg1" = "--list" ]; then
python /bin/portal_bin/portalDB.py "-L"
elif [ "$arg1" = "-h" ]; then
portal_help
elif [ "$arg1" = "--help" ]; then
portal_help
else
portal_help
fi