Update cd with new features

This commit is contained in:
Maxwell 2024-07-04 09:49:07 +10:00
parent 40519505be
commit fc59ce8717

23
main.py
View File

@ -3,18 +3,20 @@ import os
import socket import socket
import subprocess import subprocess
from colorama import Fore from colorama import Fore
from os.path import expanduser
initDirectory = os.path.dirname(os.path.realpath(__file__)) version = "0.1.0"
currentDirectory = initDirectory
version = "0.0.1"
user = os.getlogin() user = os.getlogin()
initDirectory = expanduser("~")
print("Welcome to Mash, " + user + "@" + socket.gethostname() + "! Mash is currently on version " + version) currentDirectory = initDirectory
argList = ["", ""] argList = ["", ""]
print("Welcome to Mash, " + user + "@" + socket.gethostname() + "! Mash is currently on version " + version)
try: try:
while True: while True:
os.chdir(currentDirectory)
command = input(Fore.GREEN + user + Fore.WHITE + "@" + socket.gethostname() + Fore.BLUE + " " + currentDirectory + Fore.WHITE + " > ") command = input(Fore.GREEN + user + Fore.WHITE + "@" + socket.gethostname() + Fore.BLUE + " " + currentDirectory + Fore.WHITE + " > ")
argNumber = 0 argNumber = 0
argList.clear() argList.clear()
@ -41,6 +43,17 @@ try:
exit() exit()
elif argList[0] == "version": elif argList[0] == "version":
print(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: else:
try: try:
subprocess.run(argList) subprocess.run(argList)