From 9136168689a295e0ecb6601ab5816cb916e4b725 Mon Sep 17 00:00:00 2001 From: max Date: Thu, 4 Jul 2024 13:08:32 +1000 Subject: [PATCH] Add built in "cat" (mat) and "ls" (mls) --- main.py | 19 ++++++++++++++++--- 1 file changed, 16 insertions(+), 3 deletions(-) mode change 100755 => 100644 main.py diff --git a/main.py b/main.py old mode 100755 new mode 100644 index b547263..f55cee4 --- a/main.py +++ b/main.py @@ -2,6 +2,7 @@ import os import socket import subprocess +import shutil from colorama import Fore from os.path import expanduser @@ -12,6 +13,12 @@ currentDirectory = initDirectory argList = ["", ""] +if os.path.isfile(expanduser("~") + "/.config/mash/mash.conf") == True: + configFile = open(expanduser("~") + "/.config/mash/mash.conf") +else: + print("Config file does not exist. Copying default file to ~/.config/mash/mash.conf") + shutil.copyfile("/etc/mash/mash.conf", (expanduser("~") + "/.config/mash/mash.conf")) + print("Welcome to Mash, " + user + "@" + socket.gethostname() + "! Mash is currently on version " + version) try: @@ -34,7 +41,8 @@ try: print("") print("pwd Print directory you are currently in") print("cd Change your directory.") - print("cat View contents of a file.") + print("mat View contents of a file. If you're on a Unix-like OS, use 'cat' instead.") + print("mls View all files in a directory. If you're on a Unix-like OS, use 'ls' instead.") print("version Print current version of Mash.") print("exit Exit Mash.") print("") @@ -43,6 +51,11 @@ try: exit() elif argList[0] == "version": print(version) + elif argList[0] == "mat": + matFile = open(argList[1]) + print(matFile.read()) + elif argList[0] == "mls": + os.listdir(currentDirectory) elif argList[0] == "cd": try: directoryForCD = argList[1] @@ -59,7 +72,7 @@ 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 Exception: + print("Looks like there was an error. Exiting...") except KeyboardInterrupt: print(" detected! Exiting...")