myshell-py 0.3.5__tar.gz → 0.4.0__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (70) hide show
  1. {myshell_py-0.3.5 → myshell_py-0.4.0}/PKG-INFO +86 -51
  2. {myshell_py-0.3.5 → myshell_py-0.4.0}/README.md +85 -50
  3. {myshell_py-0.3.5 → myshell_py-0.4.0}/myshell/builtins.py +8 -0
  4. {myshell_py-0.3.5 → myshell_py-0.4.0}/myshell/cli.py +47 -4
  5. {myshell_py-0.3.5 → myshell_py-0.4.0}/myshell/guide.py +4 -2
  6. myshell_py-0.4.0/myshell/procs.py +411 -0
  7. myshell_py-0.4.0/myshell/sched.py +605 -0
  8. myshell_py-0.4.0/myshell/textedit.py +273 -0
  9. {myshell_py-0.3.5 → myshell_py-0.4.0}/pyproject.toml +1 -1
  10. {myshell_py-0.3.5 → myshell_py-0.4.0}/tests/test_jobs.py +11 -0
  11. myshell_py-0.4.0/tests/test_procs.py +151 -0
  12. myshell_py-0.4.0/tests/test_sched.py +177 -0
  13. myshell_py-0.4.0/tests/test_startup.py +52 -0
  14. myshell_py-0.4.0/tests/test_textedit.py +106 -0
  15. {myshell_py-0.3.5 → myshell_py-0.4.0}/.gitignore +0 -0
  16. {myshell_py-0.3.5 → myshell_py-0.4.0}/myshell/__init__.py +0 -0
  17. {myshell_py-0.3.5 → myshell_py-0.4.0}/myshell/__main__.py +0 -0
  18. {myshell_py-0.3.5 → myshell_py-0.4.0}/myshell/aliases.py +0 -0
  19. {myshell_py-0.3.5 → myshell_py-0.4.0}/myshell/arith.py +0 -0
  20. {myshell_py-0.3.5 → myshell_py-0.4.0}/myshell/compat.py +0 -0
  21. {myshell_py-0.3.5 → myshell_py-0.4.0}/myshell/completion.py +0 -0
  22. {myshell_py-0.3.5 → myshell_py-0.4.0}/myshell/coreutils.py +0 -0
  23. {myshell_py-0.3.5 → myshell_py-0.4.0}/myshell/editor.py +0 -0
  24. {myshell_py-0.3.5 → myshell_py-0.4.0}/myshell/errors.py +0 -0
  25. {myshell_py-0.3.5 → myshell_py-0.4.0}/myshell/executor.py +0 -0
  26. {myshell_py-0.3.5 → myshell_py-0.4.0}/myshell/expand.py +0 -0
  27. {myshell_py-0.3.5 → myshell_py-0.4.0}/myshell/heredoc.py +0 -0
  28. {myshell_py-0.3.5 → myshell_py-0.4.0}/myshell/highlight.py +0 -0
  29. {myshell_py-0.3.5 → myshell_py-0.4.0}/myshell/history.py +0 -0
  30. {myshell_py-0.3.5 → myshell_py-0.4.0}/myshell/jobs.py +0 -0
  31. {myshell_py-0.3.5 → myshell_py-0.4.0}/myshell/lexer.py +0 -0
  32. {myshell_py-0.3.5 → myshell_py-0.4.0}/myshell/more_builtins.py +0 -0
  33. {myshell_py-0.3.5 → myshell_py-0.4.0}/myshell/parser.py +0 -0
  34. {myshell_py-0.3.5 → myshell_py-0.4.0}/myshell/paths.py +0 -0
  35. {myshell_py-0.3.5 → myshell_py-0.4.0}/myshell/progress.py +0 -0
  36. {myshell_py-0.3.5 → myshell_py-0.4.0}/myshell/prompt.py +0 -0
  37. {myshell_py-0.3.5 → myshell_py-0.4.0}/myshell/quiz.py +0 -0
  38. {myshell_py-0.3.5 → myshell_py-0.4.0}/myshell/state.py +0 -0
  39. {myshell_py-0.3.5 → myshell_py-0.4.0}/myshell/theme.py +0 -0
  40. {myshell_py-0.3.5 → myshell_py-0.4.0}/pytest.ini +0 -0
  41. {myshell_py-0.3.5 → myshell_py-0.4.0}/requirements.txt +0 -0
  42. {myshell_py-0.3.5 → myshell_py-0.4.0}/shell.py +0 -0
  43. {myshell_py-0.3.5 → myshell_py-0.4.0}/src/myshell/__init__.py +0 -0
  44. {myshell_py-0.3.5 → myshell_py-0.4.0}/tests/conftest.py +0 -0
  45. {myshell_py-0.3.5 → myshell_py-0.4.0}/tests/test_aliases.py +0 -0
  46. {myshell_py-0.3.5 → myshell_py-0.4.0}/tests/test_arith.py +0 -0
  47. {myshell_py-0.3.5 → myshell_py-0.4.0}/tests/test_builtins.py +0 -0
  48. {myshell_py-0.3.5 → myshell_py-0.4.0}/tests/test_cli.py +0 -0
  49. {myshell_py-0.3.5 → myshell_py-0.4.0}/tests/test_completion.py +0 -0
  50. {myshell_py-0.3.5 → myshell_py-0.4.0}/tests/test_coreutils.py +0 -0
  51. {myshell_py-0.3.5 → myshell_py-0.4.0}/tests/test_editor.py +0 -0
  52. {myshell_py-0.3.5 → myshell_py-0.4.0}/tests/test_expand.py +0 -0
  53. {myshell_py-0.3.5 → myshell_py-0.4.0}/tests/test_expansion_e2e.py +0 -0
  54. {myshell_py-0.3.5 → myshell_py-0.4.0}/tests/test_guide.py +0 -0
  55. {myshell_py-0.3.5 → myshell_py-0.4.0}/tests/test_heredoc.py +0 -0
  56. {myshell_py-0.3.5 → myshell_py-0.4.0}/tests/test_highlight.py +0 -0
  57. {myshell_py-0.3.5 → myshell_py-0.4.0}/tests/test_history.py +0 -0
  58. {myshell_py-0.3.5 → myshell_py-0.4.0}/tests/test_history_fallback.py +0 -0
  59. {myshell_py-0.3.5 → myshell_py-0.4.0}/tests/test_if.py +0 -0
  60. {myshell_py-0.3.5 → myshell_py-0.4.0}/tests/test_interactive.py +0 -0
  61. {myshell_py-0.3.5 → myshell_py-0.4.0}/tests/test_language.py +0 -0
  62. {myshell_py-0.3.5 → myshell_py-0.4.0}/tests/test_lexer.py +0 -0
  63. {myshell_py-0.3.5 → myshell_py-0.4.0}/tests/test_loops.py +0 -0
  64. {myshell_py-0.3.5 → myshell_py-0.4.0}/tests/test_more_builtins.py +0 -0
  65. {myshell_py-0.3.5 → myshell_py-0.4.0}/tests/test_parser.py +0 -0
  66. {myshell_py-0.3.5 → myshell_py-0.4.0}/tests/test_pipelines.py +0 -0
  67. {myshell_py-0.3.5 → myshell_py-0.4.0}/tests/test_prompt.py +0 -0
  68. {myshell_py-0.3.5 → myshell_py-0.4.0}/tests/test_quiz_progress.py +0 -0
  69. {myshell_py-0.3.5 → myshell_py-0.4.0}/tests/test_redirects.py +0 -0
  70. {myshell_py-0.3.5 → myshell_py-0.4.0}/tests/test_theme.py +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.5
2
2
  Name: myshell-py
3
- Version: 0.3.5
3
+ Version: 0.4.0
4
4
  Summary: A Unix-style shell written in Python, with a built-in guide.
5
5
  License: MIT
6
6
  Keywords: education,shell,terminal
@@ -20,15 +20,17 @@ A Unix-style shell written in Python. It runs on Linux and macOS with full job c
20
20
 
21
21
  ## Requirements
22
22
 
23
- - Python 3.9 or newer. Tested on 3.9 and 3.13 on Linux, macOS and Windows.
23
+ - Python 3.9 or newer. Tested on 3.9 and 3.13 on Linux, macOS and Windows (see `.github/workflows/ci.yml`).
24
24
  - `prompt_toolkit` is optional. With it you get Ctrl+R history search, grey suggestions and syntax colors. Without it the shell uses plain `input()` and readline.
25
25
  - pytest and pyflakes for development: `pip install -e ".[dev]"`
26
26
 
27
27
  ## Install and run
28
28
 
29
- uvx myshell run without installing (after the first release)
30
- uv tool install myshell install it
31
- pip install myshell
29
+ uvx myshell-py run without installing
30
+ uv tool install myshell-py install it
31
+ pip install myshell-py
32
+
33
+ The package is `myshell-py`. It installs the commands `myshell` and `myshell-py`.
32
34
 
33
35
  From a clone:
34
36
 
@@ -58,14 +60,12 @@ Pushing a tag such as `v0.2.0` runs `.github/workflows/release.yml`, which build
58
60
  ## Features
59
61
 
60
62
  Commands and operators
61
-
62
63
  - Pipes: `a | b`
63
64
  - Lists: `a; b`, `a && b`, `a || b`
64
65
  - Background jobs: `a &`
65
66
  - Comments with `#`
66
67
 
67
68
  Quoting and expansion
68
-
69
69
  - Single quotes, double quotes and backslash escapes
70
70
  - Variables: `$X`, `${X}`, `$?`, `$$`, and `$0 $1 ... $# $@ $*`
71
71
  - 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,,}`
@@ -76,14 +76,12 @@ Quoting and expansion
76
76
  - Assignments: `NAME=value`, and `NAME=value cmd` for one command
77
77
 
78
78
  Redirection
79
-
80
79
  - `< > >> 2> 2>> &> &>>`
81
80
  - `2>&1` and `1>&2`, applied left to right
82
81
  - Here-strings: `<<<`
83
82
  - Here-documents: `<<EOF` and `<<-EOF`. A quoted delimiter such as `<<'EOF'` turns expansion off.
84
83
 
85
84
  Control flow
86
-
87
85
  - `if`, `elif`, `else`, `fi`
88
86
  - `while`, `until`, `for NAME in WORDS`, with `do` and `done`. A bare `for x; do` loops over `"$@"`.
89
87
  - `case WORD in a|b) ...;; *.txt) ...;; *) ...;; esac`
@@ -93,7 +91,6 @@ Control flow
93
91
  - Blocks work on one line or across many lines
94
92
 
95
93
  Builtins
96
-
97
94
  - `echo` (with `-n -e -E`), `pwd cd exit alias unalias type which export unset source .`
98
95
  - `read` (`-r -p -d -n`), `printf` (`-v`), `set` (`-e -u -x`, `-o`, `--`), `shift local return`
99
96
  - `env` (`-i -u NAME=value`), `exec`, `trap` (EXIT, INT, TERM, HUP, USR1, USR2)
@@ -102,21 +99,22 @@ Builtins
102
99
  - `test` and `[ ]`: file, string and number checks, and `!`
103
100
  - `history`: `N`, `-c`, `-d N`, `-w [file]`, `-r [file]`
104
101
  - `guide`: lessons, cheat sheet and tips
102
+ - `kill [-s SIGNAL | -SIGNAL] PID|%JOB`, `kill -l`: stop a process or a job. On Windows every signal ends the process.
103
+ - `edit FILE`: a small full-screen editor. `^S` saves, `^X` exits, `^W` finds, `^N` finds the next match, `^G` goes to a line, `^Z` undoes. `nano` runs the same editor when your system has no `nano`.
104
+ - `cron` and `at`: scheduled tasks, see Scheduler below
105
105
 
106
106
  Commands that work on every system
107
-
108
- - `ls cat head tr sleep mkdir rm cp mv touch wc grep` are 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. Set `MYSHELL_PORTABLE=1` to always use the built-in ones.
107
+ - `ls cat head tr sleep mkdir rm cp mv touch wc grep ps top nano` are 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. Set `MYSHELL_PORTABLE=1` to always use the built-in ones.
109
108
  - They also work in pipes and `$(...)` without fork. This is what makes Pip's lessons run on Windows.
110
109
 
111
110
  Interactive use
112
-
113
111
  - Job control: Ctrl+C, Ctrl+Z, `fg`, `bg`
114
112
  - Tab completion for commands, paths and function names
115
113
  - 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=basic` turns it off.
116
114
  - After a command that takes longer than 2 seconds the shell prints `took 3.2s`. Set `SLOW_COMMAND_SECS` to change the limit, or to `off`.
117
115
  - Traps: `trap 'cmd' EXIT` runs when the shell ends
118
116
  - History saved in `~/.custom_shell_history`, limited to 1000 entries
119
- - Startup file `~/.myshellrc`
117
+ - Startup file `~/.myshellrc`. `myshell --norc` skips it, `myshell --rcfile FILE` or `MYSHELLRC=FILE` reads another one.
120
118
  - Prompt set with `PS1`. Continuation lines use `PS2`.
121
119
 
122
120
  ## Pip, the guide
@@ -124,10 +122,9 @@ Interactive use
124
122
  Pip is a small original character who lives in the shell.
125
123
 
126
124
  ,---. .--------------------------------------.
127
-
128
- ( ^ ^ ) | Hi, I am Pip, your shell guide. |
129
- \ v / '--------------------------------------'
130
- (_@_)>
125
+ ( ^ ^ ) | Hi, I am Pip, your shell guide. |
126
+ \ v / '--------------------------------------'
127
+ (_@_)>
131
128
 
132
129
  - Greets you at startup with a tip. Only on a real terminal.
133
130
  - `guide` opens a menu of 13 lessons, with `[x]` next to the ones you finished. Each step shows a command. Press Enter to run it, `s` to skip, `q` to stop.
@@ -138,20 +135,55 @@ Pip is a small original character who lives in the shell.
138
135
  - `guide off` hides Pip for the session. Put `GUIDE=off` in `~/.myshellrc` to hide Pip always.
139
136
  - Scripts, `-c` and piped input never show Pip's greeting or hints.
140
137
 
138
+ ## Scripts
139
+
140
+ Save commands in a file and run it with arguments. A first line such as `#!/usr/bin/env myshell` is a comment, so it is safe.
141
+
142
+ myshell backup.msh /data /backup # $0 is backup.msh, $1 is /data, $2 is /backup
143
+ myshell -c 'echo $1' name value # one command, with arguments
144
+
145
+ ## Processes
146
+
147
+ - `ps` lists your shell's processes. `ps -e` lists all of them.
148
+ - `top` shows a live list sorted by CPU. Options: `-n COUNT`, `-d SECONDS`, `-s cpu|mem|pid`, `-l ROWS`. Press Ctrl+C to stop.
149
+ - `kill PID`, `kill -9 PID`, `kill -s TERM %1`, `kill -l`.
150
+ - These work on Linux, macOS and Windows. On Windows `ps` and `top` read `tasklist`, so they show memory but no parent or CPU columns.
151
+
152
+ ## Scheduler
153
+
154
+ Tasks run in the background while an interactive myshell is open. Nothing runs while no myshell is open. Output goes to `~/.myshell_cron.log`. Tasks are saved in `~/.myshell_sched.json`. Set `MYSHELL_NOCRON=1` to turn the background checks off.
155
+
156
+ cron add '*/5 * * * *' echo hi # every 5 minutes
157
+ cron add '0 9 * * 1-5' backup.msh # weekdays at 09:00
158
+ cron add @daily 'rm -rf ~/tmp/*' # macros: @hourly @daily @weekly @monthly @yearly
159
+ cron # list tasks with the next run time
160
+ cron check '30 4 1,15 * *' # test a schedule
161
+ cron log # show what the tasks printed
162
+ cron rm 1 # remove task 1
163
+
164
+ at 17:30 echo hi # once, today (or tomorrow if it has passed)
165
+ at +10m echo hi # in 10 minutes. Units: m, h, d, w
166
+ at now + 2 hours echo hi
167
+ at 2026-12-01 09:30 backup.msh
168
+ at -l # list waiting tasks
169
+ at -r 1 # remove task 1
170
+
171
+ Quote the schedule so the shell does not expand the stars. If both day and weekday are set, the task runs when either matches, as in classic cron.
172
+
141
173
  ## Prompt escapes
142
174
 
143
- | Escape | Meaning |
144
- | ------------------------ | ------------------------------------------------------------ |
145
- | `\w` | current directory, `~` for home |
146
- | `\W` | last part of the directory |
147
- | `\u` `\h` | user name, host name |
148
- | `\$` | `$`, or `#` for root |
149
- | `\j` | running jobs |
150
- | `\?` | exit status of the last command |
151
- | `\n` `\e` `\\` | newline, escape, backslash |
152
- | `\t` `\T` `\A` `\@` `\d` | time (24-hour, 12-hour, HH:MM, am/pm), date |
153
- | `\g` | git branch of the current folder, empty outside a repository |
154
- | `\[` `\]` | wrap colors so line editing counts width correctly |
175
+ | Escape | Meaning |
176
+ | --- | --- |
177
+ | `\w` | current directory, `~` for home |
178
+ | `\W` | last part of the directory |
179
+ | `\u` `\h` | user name, host name |
180
+ | `\$` | `$`, or `#` for root |
181
+ | `\j` | running jobs |
182
+ | `\?` | exit status of the last command |
183
+ | `\n` `\e` `\\` | newline, escape, backslash |
184
+ | `\t` `\T` `\A` `\@` `\d` | time (24-hour, 12-hour, HH:MM, am/pm), date |
185
+ | `\g` | git branch of the current folder, empty outside a repository |
186
+ | `\[` `\]` | wrap colors so line editing counts width correctly |
155
187
 
156
188
  The default prompt adds the branch in brackets inside a git repository.
157
189
 
@@ -173,27 +205,30 @@ Example `~/.myshellrc`:
173
205
 
174
206
  ## Layout
175
207
 
176
- | File | Job |
177
- | -------------------------- | ------------------------------------------------------------ |
178
- | `cli.py` | entry point, interactive loop |
179
- | `lexer.py` | text to tokens |
180
- | `parser.py` | tokens to a tree |
181
- | `expand.py` | variables, substitution, math, globbing |
182
- | `arith.py` | the `$((...))` evaluator |
183
- | `heredoc.py` | here-document bodies |
184
- | `executor.py` | runs the tree with fork and pipes |
185
- | `jobs.py` | process groups and job control |
186
- | `builtins.py` | core builtin commands, lookup of builtins |
187
- | `more_builtins.py` | read, printf, set, env, which, trap, exec and friends |
188
- | `coreutils.py` | ls, cat, head, tr, sleep, mkdir, rm, cp, mv, touch, wc, grep |
189
- | `editor.py` `highlight.py` | optional prompt_toolkit line editor and syntax colors |
190
- | `progress.py` `quiz.py` | Pip's progress file and quiz questions |
191
- | `completion.py` | tab completion |
192
- | `prompt.py` | prompt escapes |
193
- | `theme.py` | color themes |
194
- | `guide.py` | Pip: lessons, hints, greeting |
195
- | `state.py` | variables, aliases, history, status |
196
- | `compat.py` | platform checks |
208
+ | File | Job |
209
+ | --- | --- |
210
+ | `cli.py` | entry point, interactive loop |
211
+ | `lexer.py` | text to tokens |
212
+ | `parser.py` | tokens to a tree |
213
+ | `expand.py` | variables, substitution, math, globbing |
214
+ | `arith.py` | the `$((...))` evaluator |
215
+ | `heredoc.py` | here-document bodies |
216
+ | `executor.py` | runs the tree with fork and pipes |
217
+ | `jobs.py` | process groups and job control |
218
+ | `builtins.py` | core builtin commands, lookup of builtins |
219
+ | `more_builtins.py` | read, printf, set, env, which, trap, exec and friends |
220
+ | `coreutils.py` | ls, cat, head, tr, sleep, mkdir, rm, cp, mv, touch, wc, grep |
221
+ | `editor.py` `highlight.py` | optional prompt_toolkit line editor and syntax colors |
222
+ | `progress.py` `quiz.py` | Pip's progress file and quiz questions |
223
+ | `completion.py` | tab completion |
224
+ | `prompt.py` | prompt escapes |
225
+ | `theme.py` | color themes |
226
+ | `procs.py` | ps, top, kill |
227
+ | `textedit.py` | the `edit` and `nano` editor |
228
+ | `sched.py` | cron and at |
229
+ | `guide.py` | Pip: lessons, hints, greeting |
230
+ | `state.py` | variables, aliases, history, status |
231
+ | `compat.py` | platform checks |
197
232
 
198
233
  ## Limits
199
234
 
@@ -4,15 +4,17 @@ A Unix-style shell written in Python. It runs on Linux and macOS with full job c
4
4
 
5
5
  ## Requirements
6
6
 
7
- - Python 3.9 or newer. Tested on 3.9 and 3.13 on Linux, macOS and Windows.
7
+ - Python 3.9 or newer. Tested on 3.9 and 3.13 on Linux, macOS and Windows (see `.github/workflows/ci.yml`).
8
8
  - `prompt_toolkit` is optional. With it you get Ctrl+R history search, grey suggestions and syntax colors. Without it the shell uses plain `input()` and readline.
9
9
  - pytest and pyflakes for development: `pip install -e ".[dev]"`
10
10
 
11
11
  ## Install and run
12
12
 
13
- uvx myshell run without installing (after the first release)
14
- uv tool install myshell install it
15
- pip install myshell
13
+ uvx myshell-py run without installing
14
+ uv tool install myshell-py install it
15
+ pip install myshell-py
16
+
17
+ The package is `myshell-py`. It installs the commands `myshell` and `myshell-py`.
16
18
 
17
19
  From a clone:
18
20
 
@@ -42,14 +44,12 @@ Pushing a tag such as `v0.2.0` runs `.github/workflows/release.yml`, which build
42
44
  ## Features
43
45
 
44
46
  Commands and operators
45
-
46
47
  - Pipes: `a | b`
47
48
  - Lists: `a; b`, `a && b`, `a || b`
48
49
  - Background jobs: `a &`
49
50
  - Comments with `#`
50
51
 
51
52
  Quoting and expansion
52
-
53
53
  - Single quotes, double quotes and backslash escapes
54
54
  - Variables: `$X`, `${X}`, `$?`, `$$`, and `$0 $1 ... $# $@ $*`
55
55
  - 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,,}`
@@ -60,14 +60,12 @@ Quoting and expansion
60
60
  - Assignments: `NAME=value`, and `NAME=value cmd` for one command
61
61
 
62
62
  Redirection
63
-
64
63
  - `< > >> 2> 2>> &> &>>`
65
64
  - `2>&1` and `1>&2`, applied left to right
66
65
  - Here-strings: `<<<`
67
66
  - Here-documents: `<<EOF` and `<<-EOF`. A quoted delimiter such as `<<'EOF'` turns expansion off.
68
67
 
69
68
  Control flow
70
-
71
69
  - `if`, `elif`, `else`, `fi`
72
70
  - `while`, `until`, `for NAME in WORDS`, with `do` and `done`. A bare `for x; do` loops over `"$@"`.
73
71
  - `case WORD in a|b) ...;; *.txt) ...;; *) ...;; esac`
@@ -77,7 +75,6 @@ Control flow
77
75
  - Blocks work on one line or across many lines
78
76
 
79
77
  Builtins
80
-
81
78
  - `echo` (with `-n -e -E`), `pwd cd exit alias unalias type which export unset source .`
82
79
  - `read` (`-r -p -d -n`), `printf` (`-v`), `set` (`-e -u -x`, `-o`, `--`), `shift local return`
83
80
  - `env` (`-i -u NAME=value`), `exec`, `trap` (EXIT, INT, TERM, HUP, USR1, USR2)
@@ -86,21 +83,22 @@ Builtins
86
83
  - `test` and `[ ]`: file, string and number checks, and `!`
87
84
  - `history`: `N`, `-c`, `-d N`, `-w [file]`, `-r [file]`
88
85
  - `guide`: lessons, cheat sheet and tips
86
+ - `kill [-s SIGNAL | -SIGNAL] PID|%JOB`, `kill -l`: stop a process or a job. On Windows every signal ends the process.
87
+ - `edit FILE`: a small full-screen editor. `^S` saves, `^X` exits, `^W` finds, `^N` finds the next match, `^G` goes to a line, `^Z` undoes. `nano` runs the same editor when your system has no `nano`.
88
+ - `cron` and `at`: scheduled tasks, see Scheduler below
89
89
 
90
90
  Commands that work on every system
91
-
92
- - `ls cat head tr sleep mkdir rm cp mv touch wc grep` are 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. Set `MYSHELL_PORTABLE=1` to always use the built-in ones.
91
+ - `ls cat head tr sleep mkdir rm cp mv touch wc grep ps top nano` are 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. Set `MYSHELL_PORTABLE=1` to always use the built-in ones.
93
92
  - They also work in pipes and `$(...)` without fork. This is what makes Pip's lessons run on Windows.
94
93
 
95
94
  Interactive use
96
-
97
95
  - Job control: Ctrl+C, Ctrl+Z, `fg`, `bg`
98
96
  - Tab completion for commands, paths and function names
99
97
  - 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=basic` turns it off.
100
98
  - After a command that takes longer than 2 seconds the shell prints `took 3.2s`. Set `SLOW_COMMAND_SECS` to change the limit, or to `off`.
101
99
  - Traps: `trap 'cmd' EXIT` runs when the shell ends
102
100
  - History saved in `~/.custom_shell_history`, limited to 1000 entries
103
- - Startup file `~/.myshellrc`
101
+ - Startup file `~/.myshellrc`. `myshell --norc` skips it, `myshell --rcfile FILE` or `MYSHELLRC=FILE` reads another one.
104
102
  - Prompt set with `PS1`. Continuation lines use `PS2`.
105
103
 
106
104
  ## Pip, the guide
@@ -108,10 +106,9 @@ Interactive use
108
106
  Pip is a small original character who lives in the shell.
109
107
 
110
108
  ,---. .--------------------------------------.
111
-
112
- ( ^ ^ ) | Hi, I am Pip, your shell guide. |
113
- \ v / '--------------------------------------'
114
- (_@_)>
109
+ ( ^ ^ ) | Hi, I am Pip, your shell guide. |
110
+ \ v / '--------------------------------------'
111
+ (_@_)>
115
112
 
116
113
  - Greets you at startup with a tip. Only on a real terminal.
117
114
  - `guide` opens a menu of 13 lessons, with `[x]` next to the ones you finished. Each step shows a command. Press Enter to run it, `s` to skip, `q` to stop.
@@ -122,20 +119,55 @@ Pip is a small original character who lives in the shell.
122
119
  - `guide off` hides Pip for the session. Put `GUIDE=off` in `~/.myshellrc` to hide Pip always.
123
120
  - Scripts, `-c` and piped input never show Pip's greeting or hints.
124
121
 
122
+ ## Scripts
123
+
124
+ Save commands in a file and run it with arguments. A first line such as `#!/usr/bin/env myshell` is a comment, so it is safe.
125
+
126
+ myshell backup.msh /data /backup # $0 is backup.msh, $1 is /data, $2 is /backup
127
+ myshell -c 'echo $1' name value # one command, with arguments
128
+
129
+ ## Processes
130
+
131
+ - `ps` lists your shell's processes. `ps -e` lists all of them.
132
+ - `top` shows a live list sorted by CPU. Options: `-n COUNT`, `-d SECONDS`, `-s cpu|mem|pid`, `-l ROWS`. Press Ctrl+C to stop.
133
+ - `kill PID`, `kill -9 PID`, `kill -s TERM %1`, `kill -l`.
134
+ - These work on Linux, macOS and Windows. On Windows `ps` and `top` read `tasklist`, so they show memory but no parent or CPU columns.
135
+
136
+ ## Scheduler
137
+
138
+ Tasks run in the background while an interactive myshell is open. Nothing runs while no myshell is open. Output goes to `~/.myshell_cron.log`. Tasks are saved in `~/.myshell_sched.json`. Set `MYSHELL_NOCRON=1` to turn the background checks off.
139
+
140
+ cron add '*/5 * * * *' echo hi # every 5 minutes
141
+ cron add '0 9 * * 1-5' backup.msh # weekdays at 09:00
142
+ cron add @daily 'rm -rf ~/tmp/*' # macros: @hourly @daily @weekly @monthly @yearly
143
+ cron # list tasks with the next run time
144
+ cron check '30 4 1,15 * *' # test a schedule
145
+ cron log # show what the tasks printed
146
+ cron rm 1 # remove task 1
147
+
148
+ at 17:30 echo hi # once, today (or tomorrow if it has passed)
149
+ at +10m echo hi # in 10 minutes. Units: m, h, d, w
150
+ at now + 2 hours echo hi
151
+ at 2026-12-01 09:30 backup.msh
152
+ at -l # list waiting tasks
153
+ at -r 1 # remove task 1
154
+
155
+ Quote the schedule so the shell does not expand the stars. If both day and weekday are set, the task runs when either matches, as in classic cron.
156
+
125
157
  ## Prompt escapes
126
158
 
127
- | Escape | Meaning |
128
- | ------------------------ | ------------------------------------------------------------ |
129
- | `\w` | current directory, `~` for home |
130
- | `\W` | last part of the directory |
131
- | `\u` `\h` | user name, host name |
132
- | `\$` | `$`, or `#` for root |
133
- | `\j` | running jobs |
134
- | `\?` | exit status of the last command |
135
- | `\n` `\e` `\\` | newline, escape, backslash |
136
- | `\t` `\T` `\A` `\@` `\d` | time (24-hour, 12-hour, HH:MM, am/pm), date |
137
- | `\g` | git branch of the current folder, empty outside a repository |
138
- | `\[` `\]` | wrap colors so line editing counts width correctly |
159
+ | Escape | Meaning |
160
+ | --- | --- |
161
+ | `\w` | current directory, `~` for home |
162
+ | `\W` | last part of the directory |
163
+ | `\u` `\h` | user name, host name |
164
+ | `\$` | `$`, or `#` for root |
165
+ | `\j` | running jobs |
166
+ | `\?` | exit status of the last command |
167
+ | `\n` `\e` `\\` | newline, escape, backslash |
168
+ | `\t` `\T` `\A` `\@` `\d` | time (24-hour, 12-hour, HH:MM, am/pm), date |
169
+ | `\g` | git branch of the current folder, empty outside a repository |
170
+ | `\[` `\]` | wrap colors so line editing counts width correctly |
139
171
 
140
172
  The default prompt adds the branch in brackets inside a git repository.
141
173
 
@@ -157,27 +189,30 @@ Example `~/.myshellrc`:
157
189
 
158
190
  ## Layout
159
191
 
160
- | File | Job |
161
- | -------------------------- | ------------------------------------------------------------ |
162
- | `cli.py` | entry point, interactive loop |
163
- | `lexer.py` | text to tokens |
164
- | `parser.py` | tokens to a tree |
165
- | `expand.py` | variables, substitution, math, globbing |
166
- | `arith.py` | the `$((...))` evaluator |
167
- | `heredoc.py` | here-document bodies |
168
- | `executor.py` | runs the tree with fork and pipes |
169
- | `jobs.py` | process groups and job control |
170
- | `builtins.py` | core builtin commands, lookup of builtins |
171
- | `more_builtins.py` | read, printf, set, env, which, trap, exec and friends |
172
- | `coreutils.py` | ls, cat, head, tr, sleep, mkdir, rm, cp, mv, touch, wc, grep |
173
- | `editor.py` `highlight.py` | optional prompt_toolkit line editor and syntax colors |
174
- | `progress.py` `quiz.py` | Pip's progress file and quiz questions |
175
- | `completion.py` | tab completion |
176
- | `prompt.py` | prompt escapes |
177
- | `theme.py` | color themes |
178
- | `guide.py` | Pip: lessons, hints, greeting |
179
- | `state.py` | variables, aliases, history, status |
180
- | `compat.py` | platform checks |
192
+ | File | Job |
193
+ | --- | --- |
194
+ | `cli.py` | entry point, interactive loop |
195
+ | `lexer.py` | text to tokens |
196
+ | `parser.py` | tokens to a tree |
197
+ | `expand.py` | variables, substitution, math, globbing |
198
+ | `arith.py` | the `$((...))` evaluator |
199
+ | `heredoc.py` | here-document bodies |
200
+ | `executor.py` | runs the tree with fork and pipes |
201
+ | `jobs.py` | process groups and job control |
202
+ | `builtins.py` | core builtin commands, lookup of builtins |
203
+ | `more_builtins.py` | read, printf, set, env, which, trap, exec and friends |
204
+ | `coreutils.py` | ls, cat, head, tr, sleep, mkdir, rm, cp, mv, touch, wc, grep |
205
+ | `editor.py` `highlight.py` | optional prompt_toolkit line editor and syntax colors |
206
+ | `progress.py` `quiz.py` | Pip's progress file and quiz questions |
207
+ | `completion.py` | tab completion |
208
+ | `prompt.py` | prompt escapes |
209
+ | `theme.py` | color themes |
210
+ | `procs.py` | ps, top, kill |
211
+ | `textedit.py` | the `edit` and `nano` editor |
212
+ | `sched.py` | cron and at |
213
+ | `guide.py` | Pip: lessons, hints, greeting |
214
+ | `state.py` | variables, aliases, history, status |
215
+ | `compat.py` | platform checks |
181
216
 
182
217
  ## Limits
183
218
 
@@ -7,6 +7,7 @@ from typing import Callable, Dict, List, Optional, TextIO
7
7
  from .paths import expand_user
8
8
  from . import compat, history
9
9
  from .coreutils import PORTABLE
10
+ from . import procs, sched, textedit
10
11
  from .more_builtins import EXTRA_BUILTINS, unescape
11
12
  from .errors import BreakLoop, ContinueLoop, ReturnFromFunction, ShellError, ShellExit
12
13
  from .state import ShellState
@@ -145,6 +146,10 @@ def builtin_type(state: ShellState, args: List[str], stdout: TextIO, stderr: Tex
145
146
 
146
147
  def builtin_jobs(state: ShellState, args: List[str], stdout: TextIO, stderr: TextIO) -> int:
147
148
  if not compat.HAS_FORK:
149
+ for number, proc in enumerate(state.background_jobs, 1):
150
+ if proc.poll() is None:
151
+ args_ = proc.args if isinstance(proc.args, str) else " ".join(map(str, proc.args))
152
+ print(f"[{number}] Running pid {proc.pid} {args_}", file=stdout)
148
153
  return 0
149
154
  jc = state.jobs
150
155
  jc.refresh()
@@ -488,3 +493,6 @@ BUILTINS: Dict[str, Builtin] = {
488
493
  "continue": builtin_continue,
489
494
  }
490
495
  BUILTINS.update(EXTRA_BUILTINS)
496
+ for _mod in (procs, sched, textedit):
497
+ BUILTINS.update(_mod.BUILTINS)
498
+ PORTABLE.update(getattr(_mod, "PORTABLE", {}))
@@ -16,8 +16,9 @@ from .errors import ShellError, ShellExit
16
16
  from .executor import Executor
17
17
  from .guide import greeting, guide_enabled, missing_hint, say, syntax_hint
18
18
  from .editor import make_reader
19
- from . import theme
19
+ from . import sched, theme
20
20
  from .prompt import build_continuation_prompt, build_prompt, slow_notice
21
+ from .paths import home_file
21
22
  from .state import ShellState
22
23
 
23
24
 
@@ -58,22 +59,26 @@ def run_noninteractive(state: ShellState, text: str, label: str) -> int:
58
59
  return code
59
60
 
60
61
 
61
- def run_interactive(state: ShellState) -> int:
62
+ def run_interactive(state: ShellState, use_rc: bool = True) -> int:
62
63
  state.jobs.init_terminal()
63
64
  state.load_history()
64
65
  setup_readline(state)
65
66
  reader = make_reader(state) # None means plain input() with readline
66
67
  code = 0
67
68
  try:
68
- if os.path.isfile(state.rc_file):
69
+ if use_rc and os.path.isfile(state.rc_file):
69
70
  from .builtins import source_file
70
71
  source_file(state, state.rc_file, sys.stderr)
71
72
  state.last_status = 0
72
73
  interactive = sys.stdin.isatty() # scripts piped in keep the plain "$ " prompt
74
+ if interactive:
75
+ sched.start_background()
73
76
  if interactive and guide_enabled(state):
74
77
  greeting(state, sys.stdout)
75
78
  while True:
76
79
  state.reap_jobs()
80
+ for notice in sched.SCHEDULER.take_notices():
81
+ print(notice)
77
82
  try:
78
83
  try:
79
84
  prompt = build_prompt(state) if interactive else "$ "
@@ -133,15 +138,53 @@ def run_interactive(state: ShellState) -> int:
133
138
  say(hint, "worried")
134
139
  except ShellExit as e:
135
140
  code = e.code
141
+ sched.SCHEDULER.stop()
136
142
  state.last_status = code
137
143
  run_exit_trap(state)
138
144
  state.save_history()
139
145
  return code
140
146
 
141
147
 
148
+ USAGE = """usage: myshell [--norc] [--rcfile FILE] [-c COMMAND [NAME ARG...] | SCRIPT [ARG...]]
149
+ myshell start the interactive shell
150
+ myshell -c 'echo hi' run one command and exit
151
+ myshell script.msh a b run a script file. $0 is the script, $1 and $2 are a and b
152
+ --norc do not read ~/.myshellrc
153
+ --rcfile FILE read FILE instead of ~/.myshellrc (or set MYSHELLRC)
154
+ --version print the version"""
155
+
156
+
157
+ def package_version() -> str:
158
+ try:
159
+ from importlib.metadata import version
160
+ return version("myshell-py")
161
+ except Exception:
162
+ return "unknown"
163
+
164
+
142
165
  def main(argv: Optional[List[str]] = None) -> int:
143
166
  argv = sys.argv[1:] if argv is None else argv
144
167
  state = new_shell()
168
+ use_rc = True
169
+ while argv and argv[0] in ("--norc", "--rcfile", "--version", "-V", "--help", "-h"):
170
+ flag = argv[0]
171
+ if flag == "--norc":
172
+ use_rc = False
173
+ argv = argv[1:]
174
+ elif flag == "--rcfile":
175
+ if len(argv) < 2:
176
+ print("myshell: --rcfile: option requires an argument", file=sys.stderr)
177
+ return 2
178
+ state.rc_file = argv[1]
179
+ argv = argv[2:]
180
+ elif flag in ("--version", "-V"):
181
+ print(f"myshell {package_version()}")
182
+ return 0
183
+ else:
184
+ print(USAGE)
185
+ return 0
186
+ if os.environ.get("MYSHELLRC") and state.rc_file == home_file(".myshellrc"):
187
+ state.rc_file = os.environ["MYSHELLRC"]
145
188
  if argv and argv[0] == "-c":
146
189
  if len(argv) < 2:
147
190
  print("myshell: -c: option requires an argument", file=sys.stderr)
@@ -160,4 +203,4 @@ def main(argv: Optional[List[str]] = None) -> int:
160
203
  state.script_name = argv[0]
161
204
  state.positional = list(argv[1:])
162
205
  return run_noninteractive(state, text, argv[0])
163
- return run_interactive(state)
206
+ return run_interactive(state, use_rc)
@@ -294,7 +294,9 @@ Loop control break continue break 2
294
294
  Jobs cmd & jobs fg bg wait Ctrl+C Ctrl+Z
295
295
  Builtins cd pwd echo printf read alias unalias type which export unset set env theme
296
296
  source exec trap shift local history true false : exit
297
- Files and text ls cat head tr wc grep touch mkdir rm cp mv sleep
297
+ Files and text ls cat head tr wc grep touch mkdir rm cp mv sleep edit FILE
298
+ Processes ps ps -e top kill PID kill -9 PID kill %1
299
+ Scheduling cron add '*/5 * * * *' cmd cron at 17:30 cmd at +10m cmd
298
300
  Set options set -e (stop on error) set -u (unset is error) set -x (trace)
299
301
  Typing Ctrl+R search history Right arrow takes the suggestion
300
302
  Guide guide guide TOPIC guide cheat guide tip guide quiz guide progress"""
@@ -637,4 +639,4 @@ def guide_main(state: ShellState, args: List[str], stdout: TextIO, stderr: TextI
637
639
  file=stderr)
638
640
  return 1
639
641
  run_lesson(state, lesson, stdout, make_ask())
640
- return 0
642
+ return 0