myshell-py 0.3.1__tar.gz → 0.3.5__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.
- {myshell_py-0.3.1 → myshell_py-0.3.5}/PKG-INFO +46 -38
- {myshell_py-0.3.1 → myshell_py-0.3.5}/README.md +45 -37
- {myshell_py-0.3.1 → myshell_py-0.3.5}/myshell/guide.py +57 -27
- {myshell_py-0.3.1 → myshell_py-0.3.5}/pyproject.toml +1 -1
- {myshell_py-0.3.1 → myshell_py-0.3.5}/.gitignore +0 -0
- {myshell_py-0.3.1 → myshell_py-0.3.5}/myshell/__init__.py +0 -0
- {myshell_py-0.3.1 → myshell_py-0.3.5}/myshell/__main__.py +0 -0
- {myshell_py-0.3.1 → myshell_py-0.3.5}/myshell/aliases.py +0 -0
- {myshell_py-0.3.1 → myshell_py-0.3.5}/myshell/arith.py +0 -0
- {myshell_py-0.3.1 → myshell_py-0.3.5}/myshell/builtins.py +0 -0
- {myshell_py-0.3.1 → myshell_py-0.3.5}/myshell/cli.py +0 -0
- {myshell_py-0.3.1 → myshell_py-0.3.5}/myshell/compat.py +0 -0
- {myshell_py-0.3.1 → myshell_py-0.3.5}/myshell/completion.py +0 -0
- {myshell_py-0.3.1 → myshell_py-0.3.5}/myshell/coreutils.py +0 -0
- {myshell_py-0.3.1 → myshell_py-0.3.5}/myshell/editor.py +0 -0
- {myshell_py-0.3.1 → myshell_py-0.3.5}/myshell/errors.py +0 -0
- {myshell_py-0.3.1 → myshell_py-0.3.5}/myshell/executor.py +0 -0
- {myshell_py-0.3.1 → myshell_py-0.3.5}/myshell/expand.py +0 -0
- {myshell_py-0.3.1 → myshell_py-0.3.5}/myshell/heredoc.py +0 -0
- {myshell_py-0.3.1 → myshell_py-0.3.5}/myshell/highlight.py +0 -0
- {myshell_py-0.3.1 → myshell_py-0.3.5}/myshell/history.py +0 -0
- {myshell_py-0.3.1 → myshell_py-0.3.5}/myshell/jobs.py +0 -0
- {myshell_py-0.3.1 → myshell_py-0.3.5}/myshell/lexer.py +0 -0
- {myshell_py-0.3.1 → myshell_py-0.3.5}/myshell/more_builtins.py +0 -0
- {myshell_py-0.3.1 → myshell_py-0.3.5}/myshell/parser.py +0 -0
- {myshell_py-0.3.1 → myshell_py-0.3.5}/myshell/paths.py +0 -0
- {myshell_py-0.3.1 → myshell_py-0.3.5}/myshell/progress.py +0 -0
- {myshell_py-0.3.1 → myshell_py-0.3.5}/myshell/prompt.py +0 -0
- {myshell_py-0.3.1 → myshell_py-0.3.5}/myshell/quiz.py +0 -0
- {myshell_py-0.3.1 → myshell_py-0.3.5}/myshell/state.py +0 -0
- {myshell_py-0.3.1 → myshell_py-0.3.5}/myshell/theme.py +0 -0
- {myshell_py-0.3.1 → myshell_py-0.3.5}/pytest.ini +0 -0
- {myshell_py-0.3.1 → myshell_py-0.3.5}/requirements.txt +0 -0
- {myshell_py-0.3.1 → myshell_py-0.3.5}/shell.py +0 -0
- {myshell_py-0.3.1 → myshell_py-0.3.5}/src/myshell/__init__.py +0 -0
- {myshell_py-0.3.1 → myshell_py-0.3.5}/tests/conftest.py +0 -0
- {myshell_py-0.3.1 → myshell_py-0.3.5}/tests/test_aliases.py +0 -0
- {myshell_py-0.3.1 → myshell_py-0.3.5}/tests/test_arith.py +0 -0
- {myshell_py-0.3.1 → myshell_py-0.3.5}/tests/test_builtins.py +0 -0
- {myshell_py-0.3.1 → myshell_py-0.3.5}/tests/test_cli.py +0 -0
- {myshell_py-0.3.1 → myshell_py-0.3.5}/tests/test_completion.py +0 -0
- {myshell_py-0.3.1 → myshell_py-0.3.5}/tests/test_coreutils.py +0 -0
- {myshell_py-0.3.1 → myshell_py-0.3.5}/tests/test_editor.py +0 -0
- {myshell_py-0.3.1 → myshell_py-0.3.5}/tests/test_expand.py +0 -0
- {myshell_py-0.3.1 → myshell_py-0.3.5}/tests/test_expansion_e2e.py +0 -0
- {myshell_py-0.3.1 → myshell_py-0.3.5}/tests/test_guide.py +0 -0
- {myshell_py-0.3.1 → myshell_py-0.3.5}/tests/test_heredoc.py +0 -0
- {myshell_py-0.3.1 → myshell_py-0.3.5}/tests/test_highlight.py +0 -0
- {myshell_py-0.3.1 → myshell_py-0.3.5}/tests/test_history.py +0 -0
- {myshell_py-0.3.1 → myshell_py-0.3.5}/tests/test_history_fallback.py +0 -0
- {myshell_py-0.3.1 → myshell_py-0.3.5}/tests/test_if.py +0 -0
- {myshell_py-0.3.1 → myshell_py-0.3.5}/tests/test_interactive.py +0 -0
- {myshell_py-0.3.1 → myshell_py-0.3.5}/tests/test_jobs.py +0 -0
- {myshell_py-0.3.1 → myshell_py-0.3.5}/tests/test_language.py +0 -0
- {myshell_py-0.3.1 → myshell_py-0.3.5}/tests/test_lexer.py +0 -0
- {myshell_py-0.3.1 → myshell_py-0.3.5}/tests/test_loops.py +0 -0
- {myshell_py-0.3.1 → myshell_py-0.3.5}/tests/test_more_builtins.py +0 -0
- {myshell_py-0.3.1 → myshell_py-0.3.5}/tests/test_parser.py +0 -0
- {myshell_py-0.3.1 → myshell_py-0.3.5}/tests/test_pipelines.py +0 -0
- {myshell_py-0.3.1 → myshell_py-0.3.5}/tests/test_prompt.py +0 -0
- {myshell_py-0.3.1 → myshell_py-0.3.5}/tests/test_quiz_progress.py +0 -0
- {myshell_py-0.3.1 → myshell_py-0.3.5}/tests/test_redirects.py +0 -0
- {myshell_py-0.3.1 → myshell_py-0.3.5}/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.
|
|
3
|
+
Version: 0.3.5
|
|
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,7 +20,7 @@ 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.
|
|
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
|
|
|
@@ -58,12 +58,14 @@ Pushing a tag such as `v0.2.0` runs `.github/workflows/release.yml`, which build
|
|
|
58
58
|
## Features
|
|
59
59
|
|
|
60
60
|
Commands and operators
|
|
61
|
+
|
|
61
62
|
- Pipes: `a | b`
|
|
62
63
|
- Lists: `a; b`, `a && b`, `a || b`
|
|
63
64
|
- Background jobs: `a &`
|
|
64
65
|
- Comments with `#`
|
|
65
66
|
|
|
66
67
|
Quoting and expansion
|
|
68
|
+
|
|
67
69
|
- Single quotes, double quotes and backslash escapes
|
|
68
70
|
- Variables: `$X`, `${X}`, `$?`, `$$`, and `$0 $1 ... $# $@ $*`
|
|
69
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,,}`
|
|
@@ -74,12 +76,14 @@ Quoting and expansion
|
|
|
74
76
|
- Assignments: `NAME=value`, and `NAME=value cmd` for one command
|
|
75
77
|
|
|
76
78
|
Redirection
|
|
79
|
+
|
|
77
80
|
- `< > >> 2> 2>> &> &>>`
|
|
78
81
|
- `2>&1` and `1>&2`, applied left to right
|
|
79
82
|
- Here-strings: `<<<`
|
|
80
83
|
- Here-documents: `<<EOF` and `<<-EOF`. A quoted delimiter such as `<<'EOF'` turns expansion off.
|
|
81
84
|
|
|
82
85
|
Control flow
|
|
86
|
+
|
|
83
87
|
- `if`, `elif`, `else`, `fi`
|
|
84
88
|
- `while`, `until`, `for NAME in WORDS`, with `do` and `done`. A bare `for x; do` loops over `"$@"`.
|
|
85
89
|
- `case WORD in a|b) ...;; *.txt) ...;; *) ...;; esac`
|
|
@@ -89,6 +93,7 @@ Control flow
|
|
|
89
93
|
- Blocks work on one line or across many lines
|
|
90
94
|
|
|
91
95
|
Builtins
|
|
96
|
+
|
|
92
97
|
- `echo` (with `-n -e -E`), `pwd cd exit alias unalias type which export unset source .`
|
|
93
98
|
- `read` (`-r -p -d -n`), `printf` (`-v`), `set` (`-e -u -x`, `-o`, `--`), `shift local return`
|
|
94
99
|
- `env` (`-i -u NAME=value`), `exec`, `trap` (EXIT, INT, TERM, HUP, USR1, USR2)
|
|
@@ -99,10 +104,12 @@ Builtins
|
|
|
99
104
|
- `guide`: lessons, cheat sheet and tips
|
|
100
105
|
|
|
101
106
|
Commands that work on every system
|
|
107
|
+
|
|
102
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.
|
|
103
109
|
- They also work in pipes and `$(...)` without fork. This is what makes Pip's lessons run on Windows.
|
|
104
110
|
|
|
105
111
|
Interactive use
|
|
112
|
+
|
|
106
113
|
- Job control: Ctrl+C, Ctrl+Z, `fg`, `bg`
|
|
107
114
|
- Tab completion for commands, paths and function names
|
|
108
115
|
- 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.
|
|
@@ -117,9 +124,10 @@ Interactive use
|
|
|
117
124
|
Pip is a small original character who lives in the shell.
|
|
118
125
|
|
|
119
126
|
,---. .--------------------------------------.
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
127
|
+
|
|
128
|
+
( ^ ^ ) | Hi, I am Pip, your shell guide. |
|
|
129
|
+
\ v / '--------------------------------------'
|
|
130
|
+
(_@_)>
|
|
123
131
|
|
|
124
132
|
- Greets you at startup with a tip. Only on a real terminal.
|
|
125
133
|
- `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.
|
|
@@ -132,18 +140,18 @@ Pip is a small original character who lives in the shell.
|
|
|
132
140
|
|
|
133
141
|
## Prompt escapes
|
|
134
142
|
|
|
135
|
-
| Escape
|
|
136
|
-
|
|
|
137
|
-
| `\w`
|
|
138
|
-
| `\W`
|
|
139
|
-
| `\u` `\h`
|
|
140
|
-
| `\$`
|
|
141
|
-
| `\j`
|
|
142
|
-
| `\?`
|
|
143
|
-
| `\n` `\e` `\\`
|
|
144
|
-
| `\t` `\T` `\A` `\@` `\d` | time (24-hour, 12-hour, HH:MM, am/pm), date
|
|
145
|
-
| `\g`
|
|
146
|
-
| `\[` `\]`
|
|
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 |
|
|
147
155
|
|
|
148
156
|
The default prompt adds the branch in brackets inside a git repository.
|
|
149
157
|
|
|
@@ -165,27 +173,27 @@ Example `~/.myshellrc`:
|
|
|
165
173
|
|
|
166
174
|
## Layout
|
|
167
175
|
|
|
168
|
-
| File
|
|
169
|
-
|
|
|
170
|
-
| `cli.py`
|
|
171
|
-
| `lexer.py`
|
|
172
|
-
| `parser.py`
|
|
173
|
-
| `expand.py`
|
|
174
|
-
| `arith.py`
|
|
175
|
-
| `heredoc.py`
|
|
176
|
-
| `executor.py`
|
|
177
|
-
| `jobs.py`
|
|
178
|
-
| `builtins.py`
|
|
179
|
-
| `more_builtins.py`
|
|
180
|
-
| `coreutils.py`
|
|
181
|
-
| `editor.py` `highlight.py` | optional prompt_toolkit line editor and syntax colors
|
|
182
|
-
| `progress.py` `quiz.py`
|
|
183
|
-
| `completion.py`
|
|
184
|
-
| `prompt.py`
|
|
185
|
-
| `theme.py`
|
|
186
|
-
| `guide.py`
|
|
187
|
-
| `state.py`
|
|
188
|
-
| `compat.py`
|
|
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 |
|
|
189
197
|
|
|
190
198
|
## Limits
|
|
191
199
|
|
|
@@ -4,7 +4,7 @@ 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.
|
|
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
|
|
|
@@ -42,12 +42,14 @@ Pushing a tag such as `v0.2.0` runs `.github/workflows/release.yml`, which build
|
|
|
42
42
|
## Features
|
|
43
43
|
|
|
44
44
|
Commands and operators
|
|
45
|
+
|
|
45
46
|
- Pipes: `a | b`
|
|
46
47
|
- Lists: `a; b`, `a && b`, `a || b`
|
|
47
48
|
- Background jobs: `a &`
|
|
48
49
|
- Comments with `#`
|
|
49
50
|
|
|
50
51
|
Quoting and expansion
|
|
52
|
+
|
|
51
53
|
- Single quotes, double quotes and backslash escapes
|
|
52
54
|
- Variables: `$X`, `${X}`, `$?`, `$$`, and `$0 $1 ... $# $@ $*`
|
|
53
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,,}`
|
|
@@ -58,12 +60,14 @@ Quoting and expansion
|
|
|
58
60
|
- Assignments: `NAME=value`, and `NAME=value cmd` for one command
|
|
59
61
|
|
|
60
62
|
Redirection
|
|
63
|
+
|
|
61
64
|
- `< > >> 2> 2>> &> &>>`
|
|
62
65
|
- `2>&1` and `1>&2`, applied left to right
|
|
63
66
|
- Here-strings: `<<<`
|
|
64
67
|
- Here-documents: `<<EOF` and `<<-EOF`. A quoted delimiter such as `<<'EOF'` turns expansion off.
|
|
65
68
|
|
|
66
69
|
Control flow
|
|
70
|
+
|
|
67
71
|
- `if`, `elif`, `else`, `fi`
|
|
68
72
|
- `while`, `until`, `for NAME in WORDS`, with `do` and `done`. A bare `for x; do` loops over `"$@"`.
|
|
69
73
|
- `case WORD in a|b) ...;; *.txt) ...;; *) ...;; esac`
|
|
@@ -73,6 +77,7 @@ Control flow
|
|
|
73
77
|
- Blocks work on one line or across many lines
|
|
74
78
|
|
|
75
79
|
Builtins
|
|
80
|
+
|
|
76
81
|
- `echo` (with `-n -e -E`), `pwd cd exit alias unalias type which export unset source .`
|
|
77
82
|
- `read` (`-r -p -d -n`), `printf` (`-v`), `set` (`-e -u -x`, `-o`, `--`), `shift local return`
|
|
78
83
|
- `env` (`-i -u NAME=value`), `exec`, `trap` (EXIT, INT, TERM, HUP, USR1, USR2)
|
|
@@ -83,10 +88,12 @@ Builtins
|
|
|
83
88
|
- `guide`: lessons, cheat sheet and tips
|
|
84
89
|
|
|
85
90
|
Commands that work on every system
|
|
91
|
+
|
|
86
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.
|
|
87
93
|
- They also work in pipes and `$(...)` without fork. This is what makes Pip's lessons run on Windows.
|
|
88
94
|
|
|
89
95
|
Interactive use
|
|
96
|
+
|
|
90
97
|
- Job control: Ctrl+C, Ctrl+Z, `fg`, `bg`
|
|
91
98
|
- Tab completion for commands, paths and function names
|
|
92
99
|
- 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.
|
|
@@ -101,9 +108,10 @@ Interactive use
|
|
|
101
108
|
Pip is a small original character who lives in the shell.
|
|
102
109
|
|
|
103
110
|
,---. .--------------------------------------.
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
111
|
+
|
|
112
|
+
( ^ ^ ) | Hi, I am Pip, your shell guide. |
|
|
113
|
+
\ v / '--------------------------------------'
|
|
114
|
+
(_@_)>
|
|
107
115
|
|
|
108
116
|
- Greets you at startup with a tip. Only on a real terminal.
|
|
109
117
|
- `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.
|
|
@@ -116,18 +124,18 @@ Pip is a small original character who lives in the shell.
|
|
|
116
124
|
|
|
117
125
|
## Prompt escapes
|
|
118
126
|
|
|
119
|
-
| Escape
|
|
120
|
-
|
|
|
121
|
-
| `\w`
|
|
122
|
-
| `\W`
|
|
123
|
-
| `\u` `\h`
|
|
124
|
-
| `\$`
|
|
125
|
-
| `\j`
|
|
126
|
-
| `\?`
|
|
127
|
-
| `\n` `\e` `\\`
|
|
128
|
-
| `\t` `\T` `\A` `\@` `\d` | time (24-hour, 12-hour, HH:MM, am/pm), date
|
|
129
|
-
| `\g`
|
|
130
|
-
| `\[` `\]`
|
|
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 |
|
|
131
139
|
|
|
132
140
|
The default prompt adds the branch in brackets inside a git repository.
|
|
133
141
|
|
|
@@ -149,27 +157,27 @@ Example `~/.myshellrc`:
|
|
|
149
157
|
|
|
150
158
|
## Layout
|
|
151
159
|
|
|
152
|
-
| File
|
|
153
|
-
|
|
|
154
|
-
| `cli.py`
|
|
155
|
-
| `lexer.py`
|
|
156
|
-
| `parser.py`
|
|
157
|
-
| `expand.py`
|
|
158
|
-
| `arith.py`
|
|
159
|
-
| `heredoc.py`
|
|
160
|
-
| `executor.py`
|
|
161
|
-
| `jobs.py`
|
|
162
|
-
| `builtins.py`
|
|
163
|
-
| `more_builtins.py`
|
|
164
|
-
| `coreutils.py`
|
|
165
|
-
| `editor.py` `highlight.py` | optional prompt_toolkit line editor and syntax colors
|
|
166
|
-
| `progress.py` `quiz.py`
|
|
167
|
-
| `completion.py`
|
|
168
|
-
| `prompt.py`
|
|
169
|
-
| `theme.py`
|
|
170
|
-
| `guide.py`
|
|
171
|
-
| `state.py`
|
|
172
|
-
| `compat.py`
|
|
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 |
|
|
173
181
|
|
|
174
182
|
## Limits
|
|
175
183
|
|
|
@@ -23,6 +23,7 @@ from pathlib import Path
|
|
|
23
23
|
from typing import Callable, List, Optional, TextIO
|
|
24
24
|
|
|
25
25
|
from . import compat, history, progress, quiz, theme
|
|
26
|
+
from .errors import ShellError
|
|
26
27
|
from .state import ShellState
|
|
27
28
|
|
|
28
29
|
# --- the character ---------------------------------------------------------
|
|
@@ -114,7 +115,9 @@ def build_lessons() -> List[Lesson]:
|
|
|
114
115
|
"a trailing & starts one, jobs lists them and wait waits.")])
|
|
115
116
|
return [
|
|
116
117
|
Lesson("basics", "First steps", "run commands and move around", [
|
|
117
|
-
Step("A shell runs commands. echo prints text.
|
|
118
|
+
Step("A shell runs commands. echo prints text. Put the text in quotes. "
|
|
119
|
+
"The shell removes the quotes, so echo prints only the words.",
|
|
120
|
+
'echo "hello from myshell"'),
|
|
118
121
|
Step("pwd shows the folder you are in.", "pwd"),
|
|
119
122
|
Step("cd moves you to another folder. cd - jumps back.", "cd / && pwd && cd -"),
|
|
120
123
|
Step("Tab completes commands and file names. Press it twice to see choices. "
|
|
@@ -122,9 +125,9 @@ def build_lessons() -> List[Lesson]:
|
|
|
122
125
|
]),
|
|
123
126
|
Lesson("pipes", "Pipes and files", "connect commands and save output", [
|
|
124
127
|
Step("A pipe sends the output of one command into the next.",
|
|
125
|
-
|
|
128
|
+
'echo "hello" | tr a-z A-Z'),
|
|
126
129
|
Step("> writes output to a file. >> adds to the end of a file.",
|
|
127
|
-
f
|
|
130
|
+
f'echo "first" > {demo}; echo "second" >> {demo}; cat {demo}; rm {demo}'),
|
|
128
131
|
Step("2>&1 sends error messages down the same path as normal output.",
|
|
129
132
|
"ls /no/such/folder 2>&1 | head -1"),
|
|
130
133
|
Step("A here-string feeds a line of text to a command as input.",
|
|
@@ -134,17 +137,22 @@ def build_lessons() -> List[Lesson]:
|
|
|
134
137
|
]),
|
|
135
138
|
Lesson("variables", "Variables and math", "store values and calculate", [
|
|
136
139
|
Step("Set a variable with NAME=value. Read it with $NAME.",
|
|
137
|
-
|
|
140
|
+
'demo=world; echo "hello $demo"; unset demo'),
|
|
138
141
|
Step("Put math inside $(( )). It handles + - * / % and more.",
|
|
139
142
|
"echo $((6 * 7))"),
|
|
140
143
|
Step("Variables work inside math too, with += and similar.",
|
|
141
|
-
|
|
144
|
+
'n=5; n=$((n + 1)); echo "n is $n"; unset n'),
|
|
142
145
|
Step("$( ) captures the output of a command. Backticks do the same.",
|
|
143
|
-
|
|
146
|
+
'echo "I am in $(pwd)"'),
|
|
144
147
|
Step("$? holds the exit status of the last command. 0 means success.",
|
|
145
148
|
"true; echo $?; false; echo $?"),
|
|
146
149
|
]),
|
|
147
150
|
Lesson("quotes", "Quotes and wildcards", "control what the shell changes", [
|
|
151
|
+
Step("Quotes mark where text starts and ends. The shell removes them before the "
|
|
152
|
+
"command runs, so echo prints the words without the quote marks.",
|
|
153
|
+
'echo "hello"'),
|
|
154
|
+
Step("To print the quote marks, put them inside the other kind of quote.",
|
|
155
|
+
"""echo '"hello"'"""),
|
|
148
156
|
Step("Single quotes keep text exactly as typed.",
|
|
149
157
|
"echo '$HOME stays as typed'"),
|
|
150
158
|
Step("Double quotes allow variables and keep spaces together.",
|
|
@@ -157,15 +165,15 @@ def build_lessons() -> List[Lesson]:
|
|
|
157
165
|
]),
|
|
158
166
|
Lesson("logic", "Choices and loops", "decide and repeat", [
|
|
159
167
|
Step("&& runs the next command only after success. || runs it after failure.",
|
|
160
|
-
|
|
168
|
+
'true && echo "yes"; false || echo "fallback"'),
|
|
161
169
|
Step("if tests a condition. [ ] compares numbers, text and files.",
|
|
162
|
-
|
|
170
|
+
'if [ 3 -gt 2 ]; then echo "bigger"; else echo "smaller"; fi'),
|
|
163
171
|
Step("for repeats a command for each item in a list.",
|
|
164
|
-
|
|
172
|
+
'for n in 1 2 3; do echo "number $n"; done'),
|
|
165
173
|
Step("while repeats as long as a test passes. break leaves a loop early.",
|
|
166
|
-
|
|
174
|
+
'i=0; while [ $i -lt 5 ]; do i=$((i+1)); [ $i = 3 ] && break; echo "i is $i"; done; unset i'),
|
|
167
175
|
Step("File tests: -f is a file, -d is a folder, -e exists.",
|
|
168
|
-
|
|
176
|
+
'[ -d . ] && echo ". is a folder"'),
|
|
169
177
|
]),
|
|
170
178
|
Lesson("jobs", "Background jobs", "run several things at once", [
|
|
171
179
|
*background,
|
|
@@ -174,7 +182,7 @@ def build_lessons() -> List[Lesson]:
|
|
|
174
182
|
]),
|
|
175
183
|
Lesson("functions", "Functions and arguments", "name a few commands and reuse them", [
|
|
176
184
|
Step("A function groups commands under a name. Call it like any command.",
|
|
177
|
-
|
|
185
|
+
'pip_hi() { echo "hello $1"; }; pip_hi Pip'),
|
|
178
186
|
Step("$1, $2 ... are the arguments. $# counts them. $@ lists them all.",
|
|
179
187
|
'pip_args() { echo "$# arguments: $@"; }; pip_args one "two words" three'),
|
|
180
188
|
Step('Use "$@" in quotes to pass every argument on, with spaces kept.',
|
|
@@ -185,7 +193,7 @@ def build_lessons() -> List[Lesson]:
|
|
|
185
193
|
"x=outside; pip_local() { local x=inside; echo $x; }; pip_local; echo $x; unset x"),
|
|
186
194
|
Step("A for loop with no list walks over the arguments. Scripts get arguments too: "
|
|
187
195
|
"myshell script.sh a b makes $1 equal to a.",
|
|
188
|
-
|
|
196
|
+
'pip_walk() { for a; do echo "item $a"; done; }; pip_walk x y; '
|
|
189
197
|
"unset -f pip_hi pip_args pip_each pip_check pip_local pip_walk"),
|
|
190
198
|
]),
|
|
191
199
|
Lesson("expansion", "Expansions", "defaults, trimming, replacing and braces", [
|
|
@@ -207,14 +215,14 @@ def build_lessons() -> List[Lesson]:
|
|
|
207
215
|
]),
|
|
208
216
|
Lesson("case", "Case statements", "match one value against patterns", [
|
|
209
217
|
Step("case compares a word with patterns. Each arm ends with ;;.",
|
|
210
|
-
|
|
218
|
+
'case apple in apple) echo "fruit";; carrot) echo "vegetable";; esac'),
|
|
211
219
|
Step("Use | for several patterns and * as the catch-all.",
|
|
212
|
-
|
|
220
|
+
'case notes.md in *.txt|*.md) echo "text";; *.png) echo "image";; *) echo "other";; esac'),
|
|
213
221
|
Step("Patterns can use ? and [ ] too.",
|
|
214
|
-
|
|
222
|
+
'case 7 in [0-9]) echo "one digit";; *) echo "longer";; esac'),
|
|
215
223
|
Step("Inside a function, case makes a tidy menu.",
|
|
216
|
-
|
|
217
|
-
|
|
224
|
+
'pip_do() { case $1 in start) echo "starting";; stop) echo "stopping";; '
|
|
225
|
+
'*) echo "unknown $1";; esac; }; pip_do start; pip_do jump; unset -f pip_do'),
|
|
218
226
|
]),
|
|
219
227
|
Lesson("tools", "More builtins", "read, printf, set, env, which, trap and friends", [
|
|
220
228
|
Step("read puts a line of input into variables. Here it reads a here-string.",
|
|
@@ -224,11 +232,11 @@ def build_lessons() -> List[Lesson]:
|
|
|
224
232
|
Step("printf repeats its format for extra arguments.",
|
|
225
233
|
"printf '%s\\n' one two three"),
|
|
226
234
|
Step("env lists the environment. env NAME=value command runs a command with that value.",
|
|
227
|
-
|
|
235
|
+
'env PIP_COLOR=blue echo "run with a temporary value"'),
|
|
228
236
|
Step("which tells how a name runs: builtin, alias, function or program path.",
|
|
229
|
-
|
|
237
|
+
'alias pip_a="echo hi"; which echo pip_a; unalias pip_a'),
|
|
230
238
|
Step("trap runs a command when a signal or the shell exit arrives.",
|
|
231
|
-
|
|
239
|
+
'trap "echo goodbye from trap" EXIT; trap; trap - EXIT'),
|
|
232
240
|
Step("set -e stops a script at the first failure. set -u stops at an unset variable. "
|
|
233
241
|
"set -x prints each command. Turn one off with +e, +u or +x. "
|
|
234
242
|
"set -- a b c sets $1 $2 $3."),
|
|
@@ -308,7 +316,7 @@ TIPS = [
|
|
|
308
316
|
"Use ${NAME:-default} to fall back to a default value.",
|
|
309
317
|
"Use {1..5} or file.{txt,md} to save typing.",
|
|
310
318
|
"Try guide quiz to test what you know.",
|
|
311
|
-
|
|
319
|
+
'Wrap repeated commands in a function: name() { echo "hi"; }.',
|
|
312
320
|
"Type guide progress to see which lessons you finished.",
|
|
313
321
|
]
|
|
314
322
|
|
|
@@ -394,6 +402,25 @@ def make_ask() -> Ask:
|
|
|
394
402
|
return ask
|
|
395
403
|
|
|
396
404
|
|
|
405
|
+
def run_checked(state: ShellState, line: str, out: TextIO) -> None:
|
|
406
|
+
"""Run a lesson line. Pip explains syntax errors and unknown commands."""
|
|
407
|
+
state.missing_command = None
|
|
408
|
+
try:
|
|
409
|
+
state.execute(line)
|
|
410
|
+
except ShellError as e:
|
|
411
|
+
print(e, file=sys.stderr)
|
|
412
|
+
state.last_status = 2
|
|
413
|
+
hint = syntax_hint(str(e))
|
|
414
|
+
say(hint or "That line has a syntax error. Check quotes, brackets, then and fi.",
|
|
415
|
+
"worried", out)
|
|
416
|
+
except Exception as e: # a lesson must never close the shell
|
|
417
|
+
print(e, file=out)
|
|
418
|
+
if state.missing_command:
|
|
419
|
+
hint = missing_hint(state.missing_command, state)
|
|
420
|
+
if hint:
|
|
421
|
+
say(hint, "worried", out)
|
|
422
|
+
|
|
423
|
+
|
|
397
424
|
def run_lesson(state: ShellState, lesson: Lesson, out: TextIO, ask: Ask) -> bool:
|
|
398
425
|
"""Teach one lesson. Returns False when the person stops or input ends."""
|
|
399
426
|
say(f"{lesson.title}: {lesson.summary}.", "happy", out)
|
|
@@ -413,10 +440,13 @@ def run_lesson(state: ShellState, lesson: Lesson, out: TextIO, ask: Ask) -> bool
|
|
|
413
440
|
if answer.lower() == "s":
|
|
414
441
|
continue
|
|
415
442
|
saved = state.last_status
|
|
416
|
-
|
|
417
|
-
|
|
418
|
-
|
|
419
|
-
|
|
443
|
+
typed = answer.strip()
|
|
444
|
+
line = typed if typed and typed.lower() not in ("y", "yes") else step.command
|
|
445
|
+
if line != step.command:
|
|
446
|
+
say("You typed your own version. I will run it and check it.", "think", out)
|
|
447
|
+
run_checked(state, line, out)
|
|
448
|
+
if line != step.command and state.last_status == 0:
|
|
449
|
+
say(f"It ran. The lesson used: {step.command.splitlines()[0]}", "happy", out)
|
|
420
450
|
state.last_status = saved
|
|
421
451
|
print(file=out)
|
|
422
452
|
progress.mark_lesson(state.progress_file, lesson.key)
|
|
@@ -607,4 +637,4 @@ def guide_main(state: ShellState, args: List[str], stdout: TextIO, stderr: TextI
|
|
|
607
637
|
file=stderr)
|
|
608
638
|
return 1
|
|
609
639
|
run_lesson(state, lesson, stdout, make_ask())
|
|
610
|
-
return 0
|
|
640
|
+
return 0
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|