-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathmain.py
More file actions
71 lines (50 loc) · 1.49 KB
/
main.py
File metadata and controls
71 lines (50 loc) · 1.49 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
import sys
import os
from parseCommands import parseCommands
from termcolor import colored
ACCEPTED_SHELLS = ["powershell", "cmd"]
def exitMessage():
print(colored("Thanks For Using Miniature Shell!", "green"))
def shortenCWD(cwd: str):
pathSepartor = '/' if os.name == 'posix' else '\\'
idx = -1
for i in range(len(cwd)):
if cwd[i] == pathSepartor:
idx = i
idx += 1
return cwd[idx:]
def readRC():
try:
with open('config.mash', mode='r') as file:
for line in file:
if line[0] == '#':
continue
parseCommands(line)
except:
return
def main():
DEBUG: bool = False
print(colored("Welcome To Miniature Shell (mash)!", "green"))
print(colored("Type 'help' or '?' for a list of commands", "green"))
readRC()
while True:
try:
line = input(
f"{colored('mash', 'blue')} {colored(shortenCWD(os.getcwd()), 'yellow')} > ")
except KeyboardInterrupt:
print()
exitMessage()
sys.exit()
if line == 'exit':
exitMessage()
sys.exit()
elif line == 'debug':
if DEBUG:
DEBUG = False
else:
DEBUG = True
print(f'{DEBUG=}')
continue
parseCommands(line, debug=DEBUG)
if __name__ == '__main__':
main()