Update 'shell.py'
This commit is contained in:
parent
1c475e65f3
commit
d3e22d4f0c
27
shell.py
27
shell.py
|
@ -1,5 +1,4 @@
|
|||
"""pclish: a simple shell written in Python"""
|
||||
|
||||
# Import Modules
|
||||
import os
|
||||
import subprocess
|
||||
import psutil
|
||||
|
@ -7,13 +6,13 @@ import platform
|
|||
import socket
|
||||
import getpass
|
||||
|
||||
# Get System Information
|
||||
# Get System Information
|
||||
RAM = psutil.virtual_memory()
|
||||
CPU = platform.processor()
|
||||
|
||||
# Command Interpretation -- This is the core of the shell
|
||||
# Command Interpretation -- This is the core of the shell
|
||||
def execute_command(command):
|
||||
"""execute commands and handle piping"""
|
||||
# execute commands and handle piping#
|
||||
try:
|
||||
if "|" in command:
|
||||
s_in, s_out = (0, 0)
|
||||
|
@ -49,9 +48,9 @@ def execute_command(command):
|
|||
print("pclish: command not found: {}".format(command))
|
||||
|
||||
|
||||
# Commands - Commands are defined here.
|
||||
# Commands - Commands are defined here.
|
||||
def pclish_cd(path):
|
||||
"""convert to absolute path and change directory"""
|
||||
# convert to absolute path and change directory#
|
||||
try:
|
||||
os.chdir(os.path.abspath(path))
|
||||
except Exception:
|
||||
|
@ -62,17 +61,17 @@ def pclish_echo():
|
|||
print(txt)
|
||||
|
||||
def pclish_help():
|
||||
print("""pclish: here are the commands available
|
||||
print("pclish: here are the commands available
|
||||
help: shows this page
|
||||
cd: change directory
|
||||
ver: displays shell version
|
||||
ls: lists files in current dir""")
|
||||
ls: lists files in current dir")
|
||||
|
||||
def pclish_ls():
|
||||
print("""pclish: this feature is not yet supported""")
|
||||
print("pclish: this feature is not yet supported")
|
||||
|
||||
def pclish_ver():
|
||||
print("""pclish: version 0.0.2a.""")
|
||||
print("pclish: version 0.0.2a.")
|
||||
|
||||
def pclish_mkdir():
|
||||
value = input("What would you like to name this new directory:\n")
|
||||
|
@ -80,7 +79,7 @@ def pclish_mkdir():
|
|||
os.mkdir(dir)
|
||||
|
||||
def pclish_system():
|
||||
print("""System: XCU Python Based Shell Env""")
|
||||
print("System: XCU Python Based Shell Env")
|
||||
print("RAM:")
|
||||
print(RAM)
|
||||
print("CPU:")
|
||||
|
@ -91,7 +90,7 @@ def pclish_shtdwnsubsys():
|
|||
print("Shutting Down XCU Python Based Shell Env")
|
||||
exit()
|
||||
|
||||
# Shell Prompt Customization and step 2 of command interpritation
|
||||
# Shell Prompt Customization and step 2 of command interpritation
|
||||
def main():
|
||||
while True:
|
||||
inp = input(f"{getpass.getuser()}@{platform.node()}>> ")
|
||||
|
@ -117,6 +116,6 @@ def main():
|
|||
execute_command(inp)
|
||||
|
||||
|
||||
# Main
|
||||
# Main
|
||||
if '__main__' == __name__:
|
||||
main()
|
||||
|
|
Loading…
Reference in New Issue