Last active
November 12, 2017 10:24
-
-
Save fy0/982488ddbb5eafcda565923621895cb6 to your computer and use it in GitHub Desktop.
MicroPython Simple Terminal
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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