Skip to content

Instantly share code, notes, and snippets.

@fy0
Last active November 12, 2017 10:24
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save fy0/982488ddbb5eafcda565923621895cb6 to your computer and use it in GitHub Desktop.
Save fy0/982488ddbb5eafcda565923621895cb6 to your computer and use it in GitHub Desktop.
MicroPython Simple Terminal
import os
import sys
def run():
head, *data = input('> ').strip().split(' ')
if head in ['ls', 'dir']:
path = data[0] if len(data) else ''
for i in os.listdir(path):
print(i)
elif head == 'rm':
lst = os.listdir()
for i in data:
index = i.find('*')
if index != -1:
key = i[:index]
for j in lst:
if j.startswith(key):
print(j)
os.remove(j)
else:
print(i)
os.remove(i)
elif head == 'mkdir':
if not data: print('mkdir: missing operand')
else: os.mkdir(data[0])
elif head == 'cat':
if not data:
print('cat: missing filename')
return
f = open(data[0])
while True:
txt = f.read(4)
if txt:
print(txt, end='')
else:
break
del f
elif head in ['q', 'quit']:
return 'quit'
def sh():
while True:
if run() == 'quit':
break
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment