#!/usr/bin/python import os import socket import subprocess from colorama import Fore from os.path import expanduser version = "0.1.0" user = os.getlogin() initDirectory = expanduser("~") currentDirectory = initDirectory argList = ["", ""] print("Welcome to Mash, " + user + "@" + socket.gethostname() + "! Mash is currently on version " + version) try: while True: os.chdir(currentDirectory) command = input(Fore.GREEN + user + Fore.WHITE + "@" + socket.gethostname() + Fore.BLUE + " " + currentDirectory + Fore.WHITE + " > ") argNumber = 0 argList.clear() for letter in command: if letter == " ": argNumber = argNumber + 1 else: try: argList[argNumber] = argList[argNumber] + letter except Exception: argList.append(letter) if argList[0] == "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:") print("") print("pwd Print directory you are currently in") print("cd Change your directory.") print("cat View contents of a file.") print("version Print current version of Mash.") print("exit Exit Mash.") print("") print("You can also run commands installed by your system. See your OS's documentation for more information.") elif argList[0] == "exit": exit() elif argList[0] == "version": print(version) elif argList[0] == "cd": try: directoryForCD = argList[1] if directoryForCD[0] == "~": currentDirectory = expanduser("~") + directoryForCD.replace("~", "") if directoryForCD[0] == "/": currentDirectory = directoryForCD else: currentDirectory = (currentDirectory + "/" + directoryForCD) except Exception: print("Either a directory was not provided or an error occured.") else: try: subprocess.run(argList) 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...")