Add built in "cat" (mat) and "ls" (mls)
This commit is contained in:
parent
fc59ce8717
commit
9136168689
19
main.py
Executable file → Normal file
19
main.py
Executable file → Normal file
|
@ -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...")
|
||||
|
|
Loading…
Reference in New Issue
Block a user