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