From 4f130ce28c70896cc95e5356e0089cea78bea835 Mon Sep 17 00:00:00 2001 From: max Date: Wed, 3 Jul 2024 19:24:12 +1000 Subject: [PATCH] Fix a couple little bugs with a temporary fix to be worked on later --- main.py | 29 +++++++++++++++++++++-------- 1 file changed, 21 insertions(+), 8 deletions(-) diff --git a/main.py b/main.py index dbac5c5..35731f2 100755 --- a/main.py +++ b/main.py @@ -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: