mash/main.py
2024-07-03 13:31:27 +10:00

40 lines
1.2 KiB
Python
Executable File

#!/usr/bin/python
import os
import subprocess
import re
initDirectory = os.path.dirname(os.path.realpath(__file__))
currentDirectory = initDirectory
version = "0.0.1"
user = os.getlogin()
print("Welcome to Mash, " + user + "! Mash is currently on version " + version)
def grabArgument(fullCommand, commandRan):
fullCommand.replace(commandRan, "")
try:
while True:
command = input(currentDirectory + " > ")
if command == "pwd":
print(currentDirectory)
if command == "exit":
exit()
elif command == ("cat"):
try:
catFile = input("File to catalog: ")
catFileOpened = open(catFile)
print(catFileOpened.read())
except Exception:
print("File", catFile, "either doesn't exist or isn't in this directory.")
elif command == "version":
print(version)
else:
try:
subprocess.run(command)
except Exception:
print("Command", command, "either doesn't exist, isn't in the path or isn't in this directory.")
except Exception:
print("Looks like there was an error. Exiting...")
except KeyboardInterrupt:
print(" detected! Exiting...")