Linux-like shell interface for CircuitPython. ( See mpy_shell for the MicroPython version. )
Inspired by mipyshell and busybox, here is a command-line shell for your CircuitPython board carefully implementing a range of useful commands and features.
Everything is written to save RAM and Flash; command bytecode is not loaded if you don't run the command, history is stored in a file, not in RAM, pipes use flash instead of RAM, command recall and editing and tab-completion is intelligent, etc.
- place the .mpy files for your version into /lib/ on your CircuitPython device
- run
import sh
from the >>> repl
>>> import sh
dir
- List directory contents (alias forls -Flatr
)cd
- Change directorymv
- Move or rename files or directories (supports -i)ls
- List directory contents (supports -F -l -a -t -r -h -S flags)rm
- Remove files or directoriescp
- Copy files or directories (supports -i)pwd
- Print working directoryfind
- Search for files in a directory hierarchysort
- Sort lines of text files (supports -r flag)mkdir
- Make directoriesdf
- Report file system disk space usagedu
- Estimate file space usage **rmdir
- Remove empty directoriestouch
- Change file timestamps or create an empty file
vi
- vim-like Text editor **nano
- Text editor **edit
- Text editor **grep
- Search text using patterns **cat
- Concatenate and display filestail
- Output the last part of files **head
- Output the first part of files **echo
- Display a line of textmore
- View file contents page-by-page **wc
- Word, line, character, and byte countzcat
- Concatenate compressed files and output **less
- View file contents page-by-page with backward movement (similar tomore
) **hexedit
- View and edit files in hexadecimal format **
history
- Command historyuname
- Print system information **uptime
- Tell how long the system has been runninghostname
- Show or set the system's hostname **date
- Display or set the system date and timewhois
- Query domain name information **env
- Display or set environment variablessetenv
- Set environment variables (equivalent ofexport
in some contexts)export
- Set environment variablesprintenv
- Print all or part of the environmentdiff
- Compare files line by line **
curl
- Transfer data from or to a serverwget
- Non-interactive network downloader (alias forcurl
)ping
- Send ICMP ECHO_REQUEST to network hostsdig
- DNS lookup **ssh
- OpenSSH remote login client **scp
- Secure copy (remote file copy program) **telnet
- User interface to the TELNET protocol **nc
- netcat arbitrary TCP and UDP connections and listens **ifconfig
- Configure network interfaces **ftp
- File Transfer Protocol client **
pip
- Package manager - aliases to help with installing **yum
- Package manager - alias forpip
**apt
- Advanced Package Tool - alias forpip
**
tar
- Archive files **gzip
- Compress files **gunzip
- Decompress files **bzip2
- Compress files **bunzip2
- Decompress files **
python
- inbuilt - alias forrun
**sh
- inbuilt - aliasthis tool itself (you can run commands from a .sh file through this shell)git
- Distributed version control system **diff
- Compare files line by line **
locate
- Find files by name **sz
- Send files (ZModem) **rz
- Receive files (ZModem) **now
- Display the current date and time (alias fordate
) **who
- Show who is logged on **which
- Locate a commandclear
- Clear the terminal screenreboot
- Reboot the systempoweroff
- Halt, power-off, or reboot the machine **passwd
- Change user password **sleep
- Delay for a specified amount of timeunalias
- Remove alias definitions **alias
- Create an alias for a command **exit
- Exit the shellhelp
- Display help information about built-in commandsmd5sum
- Calculate MD5 checksums **sha1sum
- Calculate SHA-1 checksums **sha256sum
- Calculate SHA-256 checksums **hexedit
- View and edit files in hexadecimal format **
blink
- flash the device LED **set
- set the state of a GPIO pin **pins
- display the input coming in to a GPIO pin **adc
- display the analogue input from a GPIO **button
- display the state of the default button **photo
- take a photo from the device camera **neo_blink
- set one or more neopixel LED colours **blink_all_pins
- output pin numbers using TTL 1's and 0's to identify pins (e.g. 7 x 1-0 pulses for GPIO7) **beep
- send an analogue tone to the default speaker **freq
- set a specific analogue output to a GPIO pin (e.g. move a servo) **
display
- control the screen **print
- write some text onto the screen **showbmp
- put a graphic onto the screen **clearlcd
- erase the LCD screen
run
- execute a python program from the shell - does progressive-compilation to save space. **
hardreset
- reboot the chip **
memtest
- test memory **
temperature
- print current temperature **mag
- show the X, Y, and Z field strength from a magnetometer **gps
- display your latitude and longitude **radar
- output data from your attached radar device **
telnetd
- listen for terminal input over TCP/IP **
wifi
- control your wifi settings **
** items above marked ** have not yet been written:-
feel free to add them and send me a PR !
new commands live in sh1.py or sh0.py etc as required (we want to keep the .mpy files for each of these libs to <= 4096 bytes to save ram and disk space.)
Implement a command history that allows users to scroll through previously entered commands using the up and down arrow keys (without wasting RAM, and persists across reboots)
Add tab completion for command and file and directory names to improve user experience.
Basic support for some piping (|
) and redirection (>
, >>
, <
) to chain commands and redirect input/output.
Allow users to set, view, and use environment variables.
Support for easily running Python, using progressive compilation, enabling running larger programs that would not otherwise fit into RAM
Allow users to create command aliases for frequently used commands.
Implements a help
command that provides information about available commands and their usage.
Supports settings.toml for configuration and environment where users can customize their shell experience.
- Circuitpython is only a single thread, so you can't background
&
things. - pipes are "faked" by sending output to temp files and running commands with redirection.
- ENVironment variables come from, and write into,
settings.toml
- use ^C to exit back to the python repl >>>