Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 23 additions & 0 deletions cat.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
# The `cat` command
# Shows the contents of a given file (in pure text)
# Only works when file is in pwd (for now)

def cat(working_dir, *args):
if not args:
print("Missing argument.\nUsage: cat <filename(s)>")
return
for target in args:
files = open("files.img", 'r+')
lines = files.read().strip('\0').split('\n')
contents = []
for i, line in enumerate(lines):
if line == '!LOC=%s' % working_dir\
and lines[i+1] == '!FNAME=%s' % target:
for i in range(i+2, len(lines)):
if lines[i] and lines[i][0] == '!': break
contents.append(lines[i])
break
else:
print("File not found: %s" % target)
print('\n'.join(contents))
files.close()
2 changes: 1 addition & 1 deletion files.img
Original file line number Diff line number Diff line change
Expand Up @@ -235,7 +235,7 @@ while True:
framework.mouseMotion(event.pos)
framework.launch()

!LOC=/bin/
!LOC=/sys/
!FNAME=vis.py
# vis.py
# Basic CLI text editor
Expand Down
9 changes: 9 additions & 0 deletions ls.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
# The `ls` command
# Shows all files in pwd

def ls(working_dir, *args):
files = open("files.img", 'r+')
lines = files.read().strip('\0').split('\n')
for i, line in enumerate(lines):
if line == "!LOC=%s" % working_dir:
print(lines[i+1].strip('!FNAME='))
Binary file added pkmndp.ttf
Binary file not shown.
7 changes: 7 additions & 0 deletions pwd.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
"""
The `pwd` command
Prints the current working directory
"""

def pwd(working_dir, *args):
print(working_dir)
File renamed without changes.
9 changes: 0 additions & 9 deletions tools/cat.py

This file was deleted.

File renamed without changes.