myshell
A Unix-style shell written in Python. It runs on Linux and macOS with full job control. It also runs on Windows through a simpler fallback.
Requirements
- Python 3.9 or newer. Tested on 3.9 and 3.13 on Linux, macOS and Windows (see
.github/workflows/ci.yml). prompt_toolkitis optional. With it you get Ctrl+R history search, grey suggestions and syntax colors. Without it the shell uses plaininput()and readline.- pytest and pyflakes for development:
pip install -e ".[dev]"
Install and run
uvx myshell run without installing (after the first release)
uv tool install myshell install it
pip install myshell
From a clone:
python shell.py interactive shell
python shell.py -c "echo hi" run one command string
python shell.py script.sh a b run a script. $1 is a, $2 is b
python -m myshell same thing, as a package
uv run myshell uses pyproject.toml
myshell -c 'cmd' NAME ARG... sets $0 to NAME and $1... to the ARGs.
Run the tests
pip install -e ".[dev]"
python -m pytest
python -m pyflakes myshell tests
With uv: uv run --extra dev pytest.
Release
uv build writes dist/*.whl and dist/*.tar.gz
uv publish needs a PyPI token or trusted publishing
Pushing a tag such as v0.2.0 runs .github/workflows/release.yml, which builds and publishes with trusted publishing. Add the repository as a trusted publisher on pypi.org first (project myshell, workflow release.yml, environment pypi). Bump version in pyproject.toml before each release. If the name myshell is taken when you publish, change name in pyproject.toml. The command stays myshell.
Features
Commands and operators
- Pipes:
a | b - Lists:
a; b,a && b,a || b - Background jobs:
a & - Comments with
#
Quoting and expansion
- Single quotes, double quotes and backslash escapes
- Variables:
$X,${X},$?,$$, and$0 $1 ... $# $@ $* - Parameter expansion:
${X:-default}${X:=v}${X:?msg}${X:+alt}${#X}${X%.txt}${X%%p}${X#p}${X##p}${X/old/new}${X//old/new}${X:off:len}${X^^}${X,,} - Brace expansion:
file.{txt,md},{1..5},{a..e},{01..10},{1..10..2} - Command substitution:
$(cmd)and backticks - Arithmetic:
$((1 + 2 * x)), including+=,?:, hex and octal - Word splitting, globbing (
*,?,[ab]) and tilde (~) - Assignments:
NAME=value, andNAME=value cmdfor one command
Redirection
< > >> 2> 2>> &> &>>2>&1and1>&2, applied left to right- Here-strings:
<<< - Here-documents:
<<EOFand<<-EOF. A quoted delimiter such as<<'EOF'turns expansion off.
Control flow
if,elif,else,fiwhile,until,for NAME in WORDS, withdoanddone. A barefor x; doloops over"$@".case WORD in a|b) ...;; *.txt) ...;; *) ...;; esac- Functions:
name() { ...; }orfunction name { ...; }, with$1,$@,$#,returnandlocal - Groups:
{ a; b; } break Nandcontinue N- Blocks work on one line or across many lines
Builtins
echo(with-n -e -E),pwd cd exit alias unalias type which export unset source .read(-r -p -d -n),printf(-v),set(-e -u -x,-o,--),shift local returnenv(-i -u NAME=value),exec,trap(EXIT, INT, TERM, HUP, USR1, USR2)true false :jobs fg bg waittestand[ ]: file, string and number checks, and!history:N,-c,-d N,-w [file],-r [file]guide: lessons, cheat sheet and tips
Commands that work on every system
ls cat head tr sleep mkdir rm cp mv touch wc grepare built in. A real program of the same name on your PATH wins, so on Linux and macOS you still get GNU or BSD tools. Where there is none (plain Windows), the built-in one runs. SetMYSHELL_PORTABLE=1to always use the built-in ones.- They also work in pipes and
$(...)without fork. This is what makes Pip's lessons run on Windows.
Interactive use
- Job control: Ctrl+C, Ctrl+Z,
fg,bg - Tab completion for commands, paths and function names
- With
prompt_toolkit: Ctrl+R reverse search, grey suggestion from history (Right arrow or End takes it), colors (green known command, red unknown, yellow strings, cyan variables).MYSHELL_EDITOR=basicturns it off. - After a command that takes longer than 2 seconds the shell prints
took 3.2s. SetSLOW_COMMAND_SECSto change the limit, or tooff. - Traps:
trap 'cmd' EXITruns when the shell ends - History saved in
~/.custom_shell_history, limited to 1000 entries - Startup file
~/.myshellrc - Prompt set with
PS1. Continuation lines usePS2.
Pip, the guide
Pip is a small original character who lives in the shell.
,---. .--------------------------------------.
( ^ ^ ) | Hi, I am Pip, your shell guide. | \ v / '--------------------------------------' (@)>
- Greets you at startup with a tip. Only on a real terminal.
guideopens a menu of 13 lessons, with[x]next to the ones you finished. Each step shows a command. Press Enter to run it,sto skip,qto stop.guide TOPICjumps to one lesson. Names and numbers both work, for exampleguide pipesorguide 2.guide cheatprints a cheat sheet.guide tipprints one tip.guide listlists the topics.guide quiz [TOPIC] [N]asks N multiple-choice questions (default 5).guide progressshows finished lessons and best scores.guide progress resetclears them. Progress lives in~/.myshell_progress.json.- Explains mistakes. A mistyped command gets "Did you mean ...?". An unclosed quote,
$(or block gets a plain explanation. guide offhides Pip for the session. PutGUIDE=offin~/.myshellrcto hide Pip always.- Scripts,
-cand piped input never show Pip's greeting or hints.
Prompt escapes
| Escape | Meaning |
|---|---|
\w |
current directory, ~ for home |
\W |
last part of the directory |
\u \h |
user name, host name |
\$ |
$, or # for root |
\j |
running jobs |
\? |
exit status of the last command |
\n \e \\ |
newline, escape, backslash |
\t \T \A \@ \d |
time (24-hour, 12-hour, HH:MM, am/pm), date |
\g |
git branch of the current folder, empty outside a repository |
\[ \] |
wrap colors so line editing counts width correctly |
The default prompt adds the branch in brackets inside a git repository.
Themes
A theme sets the colors of the default prompt, the syntax colors in the editor and Pip. Every theme except default and mono also colors the text you type and the text commands print.
theme list the themes with a preview
theme ocean switch and remember (saved in ~/.myshell_theme)
theme reset back to the default
Themes: default, ocean, forest, sunset, light (for a white background) and mono (no colors). MYSHELL_THEME=ocean picks one at start and wins over the saved choice. A PS1 you set yourself keeps its own colors, and NO_COLOR turns colors off.
Example ~/.myshellrc:
PS1='\u@\h \W \$ '
PS2='more> '
alias ll='ls -l'
Layout
| File | Job |
|---|---|
cli.py |
entry point, interactive loop |
lexer.py |
text to tokens |
parser.py |
tokens to a tree |
expand.py |
variables, substitution, math, globbing |
arith.py |
the $((...)) evaluator |
heredoc.py |
here-document bodies |
executor.py |
runs the tree with fork and pipes |
jobs.py |
process groups and job control |
builtins.py |
core builtin commands, lookup of builtins |
more_builtins.py |
read, printf, set, env, which, trap, exec and friends |
coreutils.py |
ls, cat, head, tr, sleep, mkdir, rm, cp, mv, touch, wc, grep |
editor.py highlight.py |
optional prompt_toolkit line editor and syntax colors |
progress.py quiz.py |
Pip's progress file and quiz questions |
completion.py |
tab completion |
prompt.py |
prompt escapes |
theme.py |
color themes |
guide.py |
Pip: lessons, hints, greeting |
state.py |
variables, aliases, history, status |
compat.py |
platform checks |
Limits
- Only file descriptors 0, 1 and 2 are redirected.
- Here-documents do not work inside multi-line
if, loop and function blocks. - Pipes, redirects and
&afterfi,done,esacor}are errors. Socmd | while read x; do ...; donedoes not work yet. - Function bodies must be
{ ...; }groups. There are no arrays,eval,selector[[ ]]. testhas no-a,-oor parentheses.- On Windows there is no job control:
&runs in the foreground andfg,bgandwaitare unavailable. Pipelines that include built-in commands run one stage after the other, with each stage's output held in memory. - Signal traps run at the next command boundary, not in the middle of a command.
Metadata
Release files for myshell-py 0.3.1
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| myshell_py-0.3.1.tar.gz | 117.6 kB | Without provenance | Details for myshell_py-0.3.1.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| myshell_py-0.3.1-py3-none-any.whl | Python 3 | none | any | Details for myshell_py-0.3.1-py3-none-any.whl |
Total release size: 202.7 kB
Release files / myshell_py-0.3.1.tar.gz
| Download URL | myshell_py-0.3.1.tar.gz |
|---|---|
| Size | 117.6 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
49ce704cbbf1f747a90018ded3ded44c373364732994cbe0d155aa93a2cb79fc
|
|
BLAKE2b-256 checksum How to use checksums |
22df484d2f7b726702b7fd8b6660a5324f19387177bacecabff61281f1a85508
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
uv/0.13.9 {"installer":{"name":"uv","version":"0.13.9","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"26.04","id":"resolute","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}
|
Release files / myshell_py-0.3.1-py3-none-any.whl
| Download URL | myshell_py-0.3.1-py3-none-any.whl |
|---|---|
| Size | 85.1 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
ba5de90d28b88a936bc7efd6dd6b74e8be2a592192eb93fdf3c766c1ef784211
|
|
BLAKE2b-256 checksum How to use checksums |
a0b730a3423c069706430190bb7313ce55f7386f6ef89ff94973eae7ab66ea52
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
uv/0.13.9 {"installer":{"name":"uv","version":"0.13.9","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"26.04","id":"resolute","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}
|
Security for myshell-py 0.3.1
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.