Fix a couple little bugs with a temporary fix to be worked on later

This commit is contained in:
Maxwell 2024-07-03 19:24:12 +10:00
parent 2b9763cf2c
commit 4f130ce28c

29
main.py
View File

@ -1,20 +1,19 @@
#!/usr/bin/python
import os
import socket
import subprocess
import re
from colorama import Fore
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)
print("Welcome to Mash, " + user + "@" + socket.gethostname() + "! Mash is currently on version " + version)
def grabArgument(fullCommand, commandRan):
fullCommand.replace(commandRan, "")
try:
while True:
command = input(currentDirectory + " > ")
command = input(Fore.GREEN + user + Fore.WHITE + "@" + socket.gethostname() + Fore.BLUE + " " + currentDirectory + Fore.WHITE + " > ")
if command == "help":
print("This is Mash, Max's Shell. Mash has a few built in commands, which you can use to run commands, view files and interact with your system.")
print("Some commands you can run:")
@ -41,6 +40,11 @@ try:
print("That directory doesn't exist.")
else:
currentDirectory = cdDirectory
elif cdDirectory == ".":
currentDirectory == currentDirectory
elif cdDirectory == "..":
currentDirectory == currentDirectory
print("I'm working on that lol")
else:
if os.path.isdir(currentDirectory + cdDirectory) == False:
if os.path.isfile(currentDirectory + cdDirectory) == True:
@ -54,15 +58,24 @@ try:
elif command == ("cat"):
try:
catFile = input("File to catalog: ")
catFileOpened = open(catFile)
print(catFileOpened.read())
if catFile[0] == "/":
catFileOpened = open(catFile)
print(catFileOpened.read)
else:
catFileOpened = open(currentDirectory + catFile)
print(catFileOpened.read())
except Exception:
print("File", catFile, "either doesn't exist or isn't in this directory.")
elif command == "touch":
touchName = input("File name?")
elif command == "ls":
print(os.listdir())
elif command == "version":
print(version)
else:
try:
subprocess.run(command)
subprocess.run(command, shell=True)
except Exception:
print("Command", command, "either doesn't exist, isn't in the path or isn't in this directory.")
except Exception: