-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.py
78 lines (60 loc) · 1.92 KB
/
main.py
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
#!C:\Users\Michael\AppData\Local\Programs\Python\Python37-32\python.exe
"""
WISH: Windows Improved SHell
this shell aims at being much more efficient than cmd.exe,
more useful, and easier scripting.
"""
__author__ = 'Michael Gill <[email protected]>'
__version__ = '0.0a'
import argparse
import sys
import os
import colorama
import ctypes
import completer
import getcommand
def main():
"""
gather arguments and start shell.
"""
# initiate the colorama module for windows
colorama.init()
completer.init()
ctypes.windll.kernel32.SetConsoleTitleW('WISH@' + os.getcwd())
# create argument parser
parser = argparse.ArgumentParser(
description="an improved shell for Windows")
# add optional arguments
parser.add_argument(
'--script', '-s', help='script file to be run', dest='file', type=open)
parser.add_argument(
'-c', help='execute string and exit', dest='code', type=str)
parser.add_argument(
'--version',
'-v',
help='display version information and exit',
action='store_true')
# generate sorted arguments
namespace = parser.parse_args()
# -v or --version were passed
if namespace.version:
print(version)
raise SystemExit
# -s or --script were passed
if namespace.file:
sys.stderr.write('script files not yet implemented')
while True:
print(
colorama.Fore.RED + os.getlogin() + ': ' + colorama.Fore.BLUE +
os.getcwd() + colorama.Fore.GREEN + '$ ' + colorama.Fore.RESET,
end='')
try:
command = input()
if command == '':
continue
getcommand.runcommand(command)
completer.init()
ctypes.windll.kernel32.SetConsoleTitleW('WISH@' + os.getcwd())
except (EOFError, KeyboardInterrupt): # Ctrl + C or Ctrl + Z + Enter
raise SystemExit(0)
main()