-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathphellFunctions.py
More file actions
47 lines (38 loc) · 1.19 KB
/
phellFunctions.py
File metadata and controls
47 lines (38 loc) · 1.19 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
# Built-ins for phell
import os
from pathlib import Path
# Navigation
def pwd() -> str:
sys.stdout.write(os.getcwd()+"\n")
def cd(command: list) -> None:
try:
os.chdir(" ".join(command[1:]))
except Exception as e:
sys.stdout.write(str(e)+"\n")
def ls(command: list) -> None:
try:
sys.stdout.write("\n".join(os.listdir())+"\n")
except Exception as e:
sys.stdout.write(str(e)+"\n")
# Interaction
def echo(command: list) -> str:
#NOTE expand on this to single and doubel quote later.
sys.stdout.write(" ".join(command)+"\n")
def type(command: list) -> None:
if command[0] in builtIns:
sys.stdout.write(f"{command[0]} is a built in")
else:
#NOTE search PATH
pass
# Files
def cat(command: list) -> None:
# The func below returns a string but doesn't mean it is a real file.
filePath: str = os.path.abspath(command[1])
if os.path.isfile(filePath):
try:
with open(filePath, "r") as file:
sys.stdout.write(file.read())
except:
sys.stdout.write(f"Failed to open file: {command[1]}")
else:
sys.stdout.write(f"No file found or not file: {command[1]}")