From fc59ce87179f0a36ac89c73ee60396c132b297c6 Mon Sep 17 00:00:00 2001 From: max Date: Thu, 4 Jul 2024 09:49:07 +1000 Subject: [PATCH] Update cd with new features --- main.py | 23 ++++++++++++++++++----- 1 file changed, 18 insertions(+), 5 deletions(-) diff --git a/main.py b/main.py index f2d0fa2..b547263 100755 --- a/main.py +++ b/main.py @@ -3,18 +3,20 @@ import os import socket import subprocess from colorama import Fore +from os.path import expanduser -initDirectory = os.path.dirname(os.path.realpath(__file__)) -currentDirectory = initDirectory -version = "0.0.1" +version = "0.1.0" user = os.getlogin() - -print("Welcome to Mash, " + user + "@" + socket.gethostname() + "! Mash is currently on version " + version) +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() @@ -41,6 +43,17 @@ try: 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)