-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathshell.py
More file actions
152 lines (136 loc) · 5.65 KB
/
shell.py
File metadata and controls
152 lines (136 loc) · 5.65 KB
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
151
152
from os import system
# For autocomplete and suggestions
from fuzzywuzzy import fuzz
# sea shell command names
sea_shell_commands = [
"sos",
"treasure-map",
"dive",
"fish",
"review",
"forge",
"dismantle",
"rename",
"engine",
"radar",
"treasure-trail",
"glance",
"locate",
"cargo",
"kill",
"wipe",
"exit"
]
def closest_command_finder(command):
"""
Function to take a command string, find the closest matching command and return a possible match from the existing set of shell commands.
...
Parameters
----------
command : str
The command to be analysed to find the closest match
"""
closest_command = command
sys_command = sea_shell_commands[0]
fuzzratio = fuzz.ratio(command, sys_command)
for sys_command in sea_shell_commands:
if fuzz.ratio(command, sys_command) > fuzzratio and fuzz.ratio(command, sys_command)!=0:
fuzzratio = fuzz.ratio(command, sys_command)
closest_command = sys_command
return closest_command
def shell_help():
"""
Function to display the help text for the shell on startup.
"""
f = open('startup_files/startup.txt', 'r')
print(f.read())
print('\n')
def shell():
"""
Function that runs the shell.
"""
startup = 1
from_cmd_error = 0
while 1:
if startup == 1:
startup = startup + 1
_ = system('clear')
shell_help()
if (from_cmd_error == 0):
userinput = input("\033[1msea-shell@\033[94muser\033[0m$ ")
pass
else:
userinput = closest_command + " " + userinput
from_cmd_error = 0
input_arr = userinput.split()
if(input_arr[0] == sea_shell_commands[0]): # shell help
shell_help()
elif(len(input_arr) == 1 and (input_arr[0] in sea_shell_commands) and input_arr[0] != 'exit' and input_arr[0] != 'wipe' and input_arr[0] != 'engine' and input_arr[0] != 'radar' and input_arr[0] != 'locate' and input_arr[0] != 'cargo'):
system('python3 ' + input_arr[0] + '.py --help')
elif(input_arr[0] == sea_shell_commands[1]):
system('python ' + sea_shell_commands[1] + '.py ' + input_arr[0]) # man page for every command
elif(input_arr[0] == sea_shell_commands[2]): # file searcher command
system('python3 dive.py ' + input_arr[1])
elif(input_arr[0] == sea_shell_commands[3]): # file command
system('python3 fish.py ' + input_arr[1])
elif(input_arr[0] == sea_shell_commands[4]): # spell checker command
system('python3 review.py ' + input_arr[1])
elif(input_arr[0] == sea_shell_commands[5]): # make directory command
if len(input_arr) == 3:
system('python3 forge.py ' + input_arr[1] + ' ' + input_arr[2])
elif len(input_arr) == 2:
system('python3 forge.py ' + input_arr[1])
elif(input_arr[0] == sea_shell_commands[6]): # remove directory command
if len(input_arr) == 3:
system('python3 dismantle.py ' + input_arr[1] + ' ' + input_arr[2])
elif len(input_arr) == 2:
system('python3 dismantle.py ' + input_arr[1])
elif(input_arr[0] == sea_shell_commands[7]): # rename command
if len(input_arr) == 3:
system('python3 rename.py ' + input_arr[1] + input_arr[2])
elif len(input_arr) == 2:
system('python3 rename.py ' + input_arr[1])
elif(input_arr[0] == sea_shell_commands[8]): # free command
if len(input_arr) == 3:
system('python3 engine.py ' + input_arr[1] + input_arr[2])
elif len(input_arr) == 2:
system('python3 engine.py ' + input_arr[1])
elif len(input_arr) == 1:
system('python3 engine.py')
elif(input_arr[0] == sea_shell_commands[9]): # ps command
if len(input_arr) == 2:
system('python3 radar.py ' + input_arr[1])
else:
system('python3 radar.py')
elif(input_arr[0] == sea_shell_commands[10]): # tree command
if len(input_arr) == 2:
system('python3 treasure-trail.py ' + input_arr[1])
elif(input_arr[0] == sea_shell_commands[11]): # cat command
if len(input_arr) == 2:
system('python3 glance.py ' + input_arr[1])
elif(input_arr[0] == sea_shell_commands[12]): # ps command
if len(input_arr) == 2:
system('python3 locate.py ' + input_arr[1])
else:
system('python3 locate.py')
elif(input_arr[0] == sea_shell_commands[13]): # lsof command
if len(input_arr) == 2:
system('python3 cargo.py ' + input_arr[1])
else:
system('python3 cargo.py')
elif(input_arr[0] == sea_shell_commands[14]): # kill command
if len(input_arr) == 2:
system('python3 kill.py ' + input_arr[1])
elif(input_arr[0] == sea_shell_commands[15]): # clear command
_ = system('clear')
elif(input_arr[0] == sea_shell_commands[16]): # exit command
exit(0)
else:
closest_command = closest_command_finder(input_arr[0])
userinput = input(input_arr[0] + ": command not found. Did you mean " + closest_command + "? (y/n): ")
if userinput == 'y' or userinput == 'Y':
userinput = input("\033[1msea-shell@\033[94muser\033[0m$ " + closest_command)
from_cmd_error = 1;
else:
continue
shell()