myshell-py 0.3.1__tar.gz → 0.3.2__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.2}/PKG-INFO +46 -38
- {myshell_py-0.3.1 → myshell_py-0.3.2}/README.md +45 -37
- {myshell_py-0.3.1 → myshell_py-0.3.2}/myshell/guide.py +29 -22
- {myshell_py-0.3.1 → myshell_py-0.3.2}/pyproject.toml +1 -1
- {myshell_py-0.3.1 → myshell_py-0.3.2}/.gitignore +0 -0
- {myshell_py-0.3.1 → myshell_py-0.3.2}/myshell/__init__.py +0 -0
- {myshell_py-0.3.1 → myshell_py-0.3.2}/myshell/__main__.py +0 -0
- {myshell_py-0.3.1 → myshell_py-0.3.2}/myshell/aliases.py +0 -0
- {myshell_py-0.3.1 → myshell_py-0.3.2}/myshell/arith.py +0 -0
- {myshell_py-0.3.1 → myshell_py-0.3.2}/myshell/builtins.py +0 -0
- {myshell_py-0.3.1 → myshell_py-0.3.2}/myshell/cli.py +0 -0
- {myshell_py-0.3.1 → myshell_py-0.3.2}/myshell/compat.py +0 -0
- {myshell_py-0.3.1 → myshell_py-0.3.2}/myshell/completion.py +0 -0
- {myshell_py-0.3.1 → myshell_py-0.3.2}/myshell/coreutils.py +0 -0
- {myshell_py-0.3.1 → myshell_py-0.3.2}/myshell/editor.py +0 -0
- {myshell_py-0.3.1 → myshell_py-0.3.2}/myshell/errors.py +0 -0
- {myshell_py-0.3.1 → myshell_py-0.3.2}/myshell/executor.py +0 -0
- {myshell_py-0.3.1 → myshell_py-0.3.2}/myshell/expand.py +0 -0
- {myshell_py-0.3.1 → myshell_py-0.3.2}/myshell/heredoc.py +0 -0
- {myshell_py-0.3.1 → myshell_py-0.3.2}/myshell/highlight.py +0 -0
- {myshell_py-0.3.1 → myshell_py-0.3.2}/myshell/history.py +0 -0
- {myshell_py-0.3.1 → myshell_py-0.3.2}/myshell/jobs.py +0 -0
- {myshell_py-0.3.1 → myshell_py-0.3.2}/myshell/lexer.py +0 -0
- {myshell_py-0.3.1 → myshell_py-0.3.2}/myshell/more_builtins.py +0 -0
- {myshell_py-0.3.1 → myshell_py-0.3.2}/myshell/parser.py +0 -0
- {myshell_py-0.3.1 → myshell_py-0.3.2}/myshell/paths.py +0 -0
- {myshell_py-0.3.1 → myshell_py-0.3.2}/myshell/progress.py +0 -0
- {myshell_py-0.3.1 → myshell_py-0.3.2}/myshell/prompt.py +0 -0
- {myshell_py-0.3.1 → myshell_py-0.3.2}/myshell/quiz.py +0 -0
- {myshell_py-0.3.1 → myshell_py-0.3.2}/myshell/state.py +0 -0
- {myshell_py-0.3.1 → myshell_py-0.3.2}/myshell/theme.py +0 -0
- {myshell_py-0.3.1 → myshell_py-0.3.2}/pytest.ini +0 -0
- {myshell_py-0.3.1 → myshell_py-0.3.2}/requirements.txt +0 -0
- {myshell_py-0.3.1 → myshell_py-0.3.2}/shell.py +0 -0
- {myshell_py-0.3.1 → myshell_py-0.3.2}/src/myshell/__init__.py +0 -0
- {myshell_py-0.3.1 → myshell_py-0.3.2}/tests/conftest.py +0 -0
- {myshell_py-0.3.1 → myshell_py-0.3.2}/tests/test_aliases.py +0 -0
- {myshell_py-0.3.1 → myshell_py-0.3.2}/tests/test_arith.py +0 -0
- {myshell_py-0.3.1 → myshell_py-0.3.2}/tests/test_builtins.py +0 -0
- {myshell_py-0.3.1 → myshell_py-0.3.2}/tests/test_cli.py +0 -0
- {myshell_py-0.3.1 → myshell_py-0.3.2}/tests/test_completion.py +0 -0
- {myshell_py-0.3.1 → myshell_py-0.3.2}/tests/test_coreutils.py +0 -0
- {myshell_py-0.3.1 → myshell_py-0.3.2}/tests/test_editor.py +0 -0
- {myshell_py-0.3.1 → myshell_py-0.3.2}/tests/test_expand.py +0 -0
- {myshell_py-0.3.1 → myshell_py-0.3.2}/tests/test_expansion_e2e.py +0 -0
- {myshell_py-0.3.1 → myshell_py-0.3.2}/tests/test_guide.py +0 -0
- {myshell_py-0.3.1 → myshell_py-0.3.2}/tests/test_heredoc.py +0 -0
- {myshell_py-0.3.1 → myshell_py-0.3.2}/tests/test_highlight.py +0 -0
- {myshell_py-0.3.1 → myshell_py-0.3.2}/tests/test_history.py +0 -0
- {myshell_py-0.3.1 → myshell_py-0.3.2}/tests/test_history_fallback.py +0 -0
- {myshell_py-0.3.1 → myshell_py-0.3.2}/tests/test_if.py +0 -0
- {myshell_py-0.3.1 → myshell_py-0.3.2}/tests/test_interactive.py +0 -0
- {myshell_py-0.3.1 → myshell_py-0.3.2}/tests/test_jobs.py +0 -0
- {myshell_py-0.3.1 → myshell_py-0.3.2}/tests/test_language.py +0 -0
- {myshell_py-0.3.1 → myshell_py-0.3.2}/tests/test_lexer.py +0 -0
- {myshell_py-0.3.1 → myshell_py-0.3.2}/tests/test_loops.py +0 -0
- {myshell_py-0.3.1 → myshell_py-0.3.2}/tests/test_more_builtins.py +0 -0
- {myshell_py-0.3.1 → myshell_py-0.3.2}/tests/test_parser.py +0 -0
- {myshell_py-0.3.1 → myshell_py-0.3.2}/tests/test_pipelines.py +0 -0
- {myshell_py-0.3.1 → myshell_py-0.3.2}/tests/test_prompt.py +0 -0
- {myshell_py-0.3.1 → myshell_py-0.3.2}/tests/test_quiz_progress.py +0 -0
- {myshell_py-0.3.1 → myshell_py-0.3.2}/tests/test_redirects.py +0 -0
- {myshell_py-0.3.1 → myshell_py-0.3.2}/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.2
|
|
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
|
|
|
@@ -114,7 +114,9 @@ def build_lessons() -> List[Lesson]:
|
|
|
114
114
|
"a trailing & starts one, jobs lists them and wait waits.")])
|
|
115
115
|
return [
|
|
116
116
|
Lesson("basics", "First steps", "run commands and move around", [
|
|
117
|
-
Step("A shell runs commands. echo prints text.
|
|
117
|
+
Step("A shell runs commands. echo prints text. Put the text in quotes. "
|
|
118
|
+
"The shell removes the quotes, so echo prints only the words.",
|
|
119
|
+
'echo "hello from myshell"'),
|
|
118
120
|
Step("pwd shows the folder you are in.", "pwd"),
|
|
119
121
|
Step("cd moves you to another folder. cd - jumps back.", "cd / && pwd && cd -"),
|
|
120
122
|
Step("Tab completes commands and file names. Press it twice to see choices. "
|
|
@@ -122,9 +124,9 @@ def build_lessons() -> List[Lesson]:
|
|
|
122
124
|
]),
|
|
123
125
|
Lesson("pipes", "Pipes and files", "connect commands and save output", [
|
|
124
126
|
Step("A pipe sends the output of one command into the next.",
|
|
125
|
-
|
|
127
|
+
'echo "hello" | tr a-z A-Z'),
|
|
126
128
|
Step("> writes output to a file. >> adds to the end of a file.",
|
|
127
|
-
f
|
|
129
|
+
f'echo "first" > {demo}; echo "second" >> {demo}; cat {demo}; rm {demo}'),
|
|
128
130
|
Step("2>&1 sends error messages down the same path as normal output.",
|
|
129
131
|
"ls /no/such/folder 2>&1 | head -1"),
|
|
130
132
|
Step("A here-string feeds a line of text to a command as input.",
|
|
@@ -134,17 +136,22 @@ def build_lessons() -> List[Lesson]:
|
|
|
134
136
|
]),
|
|
135
137
|
Lesson("variables", "Variables and math", "store values and calculate", [
|
|
136
138
|
Step("Set a variable with NAME=value. Read it with $NAME.",
|
|
137
|
-
|
|
139
|
+
'demo=world; echo "hello $demo"; unset demo'),
|
|
138
140
|
Step("Put math inside $(( )). It handles + - * / % and more.",
|
|
139
141
|
"echo $((6 * 7))"),
|
|
140
142
|
Step("Variables work inside math too, with += and similar.",
|
|
141
|
-
|
|
143
|
+
'n=5; n=$((n + 1)); echo "n is $n"; unset n'),
|
|
142
144
|
Step("$( ) captures the output of a command. Backticks do the same.",
|
|
143
|
-
|
|
145
|
+
'echo "I am in $(pwd)"'),
|
|
144
146
|
Step("$? holds the exit status of the last command. 0 means success.",
|
|
145
147
|
"true; echo $?; false; echo $?"),
|
|
146
148
|
]),
|
|
147
149
|
Lesson("quotes", "Quotes and wildcards", "control what the shell changes", [
|
|
150
|
+
Step("Quotes mark where text starts and ends. The shell removes them before the "
|
|
151
|
+
"command runs, so echo prints the words without the quote marks.",
|
|
152
|
+
'echo "hello"'),
|
|
153
|
+
Step("To print the quote marks, put them inside the other kind of quote.",
|
|
154
|
+
"""echo '"hello"'"""),
|
|
148
155
|
Step("Single quotes keep text exactly as typed.",
|
|
149
156
|
"echo '$HOME stays as typed'"),
|
|
150
157
|
Step("Double quotes allow variables and keep spaces together.",
|
|
@@ -157,15 +164,15 @@ def build_lessons() -> List[Lesson]:
|
|
|
157
164
|
]),
|
|
158
165
|
Lesson("logic", "Choices and loops", "decide and repeat", [
|
|
159
166
|
Step("&& runs the next command only after success. || runs it after failure.",
|
|
160
|
-
|
|
167
|
+
'true && echo "yes"; false || echo "fallback"'),
|
|
161
168
|
Step("if tests a condition. [ ] compares numbers, text and files.",
|
|
162
|
-
|
|
169
|
+
'if [ 3 -gt 2 ]; then echo "bigger"; else echo "smaller"; fi'),
|
|
163
170
|
Step("for repeats a command for each item in a list.",
|
|
164
|
-
|
|
171
|
+
'for n in 1 2 3; do echo "number $n"; done'),
|
|
165
172
|
Step("while repeats as long as a test passes. break leaves a loop early.",
|
|
166
|
-
|
|
173
|
+
'i=0; while [ $i -lt 5 ]; do i=$((i+1)); [ $i = 3 ] && break; echo "i is $i"; done; unset i'),
|
|
167
174
|
Step("File tests: -f is a file, -d is a folder, -e exists.",
|
|
168
|
-
|
|
175
|
+
'[ -d . ] && echo ". is a folder"'),
|
|
169
176
|
]),
|
|
170
177
|
Lesson("jobs", "Background jobs", "run several things at once", [
|
|
171
178
|
*background,
|
|
@@ -174,7 +181,7 @@ def build_lessons() -> List[Lesson]:
|
|
|
174
181
|
]),
|
|
175
182
|
Lesson("functions", "Functions and arguments", "name a few commands and reuse them", [
|
|
176
183
|
Step("A function groups commands under a name. Call it like any command.",
|
|
177
|
-
|
|
184
|
+
'pip_hi() { echo "hello $1"; }; pip_hi Pip'),
|
|
178
185
|
Step("$1, $2 ... are the arguments. $# counts them. $@ lists them all.",
|
|
179
186
|
'pip_args() { echo "$# arguments: $@"; }; pip_args one "two words" three'),
|
|
180
187
|
Step('Use "$@" in quotes to pass every argument on, with spaces kept.',
|
|
@@ -185,7 +192,7 @@ def build_lessons() -> List[Lesson]:
|
|
|
185
192
|
"x=outside; pip_local() { local x=inside; echo $x; }; pip_local; echo $x; unset x"),
|
|
186
193
|
Step("A for loop with no list walks over the arguments. Scripts get arguments too: "
|
|
187
194
|
"myshell script.sh a b makes $1 equal to a.",
|
|
188
|
-
|
|
195
|
+
'pip_walk() { for a; do echo "item $a"; done; }; pip_walk x y; '
|
|
189
196
|
"unset -f pip_hi pip_args pip_each pip_check pip_local pip_walk"),
|
|
190
197
|
]),
|
|
191
198
|
Lesson("expansion", "Expansions", "defaults, trimming, replacing and braces", [
|
|
@@ -207,14 +214,14 @@ def build_lessons() -> List[Lesson]:
|
|
|
207
214
|
]),
|
|
208
215
|
Lesson("case", "Case statements", "match one value against patterns", [
|
|
209
216
|
Step("case compares a word with patterns. Each arm ends with ;;.",
|
|
210
|
-
|
|
217
|
+
'case apple in apple) echo "fruit";; carrot) echo "vegetable";; esac'),
|
|
211
218
|
Step("Use | for several patterns and * as the catch-all.",
|
|
212
|
-
|
|
219
|
+
'case notes.md in *.txt|*.md) echo "text";; *.png) echo "image";; *) echo "other";; esac'),
|
|
213
220
|
Step("Patterns can use ? and [ ] too.",
|
|
214
|
-
|
|
221
|
+
'case 7 in [0-9]) echo "one digit";; *) echo "longer";; esac'),
|
|
215
222
|
Step("Inside a function, case makes a tidy menu.",
|
|
216
|
-
|
|
217
|
-
|
|
223
|
+
'pip_do() { case $1 in start) echo "starting";; stop) echo "stopping";; '
|
|
224
|
+
'*) echo "unknown $1";; esac; }; pip_do start; pip_do jump; unset -f pip_do'),
|
|
218
225
|
]),
|
|
219
226
|
Lesson("tools", "More builtins", "read, printf, set, env, which, trap and friends", [
|
|
220
227
|
Step("read puts a line of input into variables. Here it reads a here-string.",
|
|
@@ -224,11 +231,11 @@ def build_lessons() -> List[Lesson]:
|
|
|
224
231
|
Step("printf repeats its format for extra arguments.",
|
|
225
232
|
"printf '%s\\n' one two three"),
|
|
226
233
|
Step("env lists the environment. env NAME=value command runs a command with that value.",
|
|
227
|
-
|
|
234
|
+
'env PIP_COLOR=blue echo "run with a temporary value"'),
|
|
228
235
|
Step("which tells how a name runs: builtin, alias, function or program path.",
|
|
229
|
-
|
|
236
|
+
'alias pip_a="echo hi"; which echo pip_a; unalias pip_a'),
|
|
230
237
|
Step("trap runs a command when a signal or the shell exit arrives.",
|
|
231
|
-
|
|
238
|
+
'trap "echo goodbye from trap" EXIT; trap; trap - EXIT'),
|
|
232
239
|
Step("set -e stops a script at the first failure. set -u stops at an unset variable. "
|
|
233
240
|
"set -x prints each command. Turn one off with +e, +u or +x. "
|
|
234
241
|
"set -- a b c sets $1 $2 $3."),
|
|
@@ -308,7 +315,7 @@ TIPS = [
|
|
|
308
315
|
"Use ${NAME:-default} to fall back to a default value.",
|
|
309
316
|
"Use {1..5} or file.{txt,md} to save typing.",
|
|
310
317
|
"Try guide quiz to test what you know.",
|
|
311
|
-
|
|
318
|
+
'Wrap repeated commands in a function: name() { echo "hi"; }.',
|
|
312
319
|
"Type guide progress to see which lessons you finished.",
|
|
313
320
|
]
|
|
314
321
|
|
|
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
|