myshell-py 0.2.0__tar.gz → 0.3.1__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.2.0 → myshell_py-0.3.1}/PKG-INFO +47 -44
- {myshell_py-0.2.0 → myshell_py-0.3.1}/README.md +46 -43
- {myshell_py-0.2.0 → myshell_py-0.3.1}/myshell/cli.py +8 -0
- {myshell_py-0.2.0 → myshell_py-0.3.1}/myshell/completion.py +3 -0
- {myshell_py-0.2.0 → myshell_py-0.3.1}/myshell/editor.py +7 -3
- {myshell_py-0.2.0 → myshell_py-0.3.1}/myshell/guide.py +7 -6
- {myshell_py-0.2.0 → myshell_py-0.3.1}/myshell/more_builtins.py +43 -0
- {myshell_py-0.2.0 → myshell_py-0.3.1}/myshell/prompt.py +11 -6
- myshell_py-0.3.1/myshell/theme.py +203 -0
- {myshell_py-0.2.0 → myshell_py-0.3.1}/pyproject.toml +2 -1
- myshell_py-0.3.1/requirements.txt +4 -0
- {myshell_py-0.2.0 → myshell_py-0.3.1}/tests/conftest.py +10 -0
- {myshell_py-0.2.0 → myshell_py-0.3.1}/tests/test_editor.py +1 -1
- {myshell_py-0.2.0 → myshell_py-0.3.1}/tests/test_guide.py +1 -1
- myshell_py-0.3.1/tests/test_theme.py +272 -0
- myshell_py-0.2.0/requirements.txt +0 -16
- {myshell_py-0.2.0 → myshell_py-0.3.1}/.gitignore +0 -0
- {myshell_py-0.2.0 → myshell_py-0.3.1}/myshell/__init__.py +0 -0
- {myshell_py-0.2.0 → myshell_py-0.3.1}/myshell/__main__.py +0 -0
- {myshell_py-0.2.0 → myshell_py-0.3.1}/myshell/aliases.py +0 -0
- {myshell_py-0.2.0 → myshell_py-0.3.1}/myshell/arith.py +0 -0
- {myshell_py-0.2.0 → myshell_py-0.3.1}/myshell/builtins.py +0 -0
- {myshell_py-0.2.0 → myshell_py-0.3.1}/myshell/compat.py +0 -0
- {myshell_py-0.2.0 → myshell_py-0.3.1}/myshell/coreutils.py +0 -0
- {myshell_py-0.2.0 → myshell_py-0.3.1}/myshell/errors.py +0 -0
- {myshell_py-0.2.0 → myshell_py-0.3.1}/myshell/executor.py +0 -0
- {myshell_py-0.2.0 → myshell_py-0.3.1}/myshell/expand.py +0 -0
- {myshell_py-0.2.0 → myshell_py-0.3.1}/myshell/heredoc.py +0 -0
- {myshell_py-0.2.0 → myshell_py-0.3.1}/myshell/highlight.py +0 -0
- {myshell_py-0.2.0 → myshell_py-0.3.1}/myshell/history.py +0 -0
- {myshell_py-0.2.0 → myshell_py-0.3.1}/myshell/jobs.py +0 -0
- {myshell_py-0.2.0 → myshell_py-0.3.1}/myshell/lexer.py +0 -0
- {myshell_py-0.2.0 → myshell_py-0.3.1}/myshell/parser.py +0 -0
- {myshell_py-0.2.0 → myshell_py-0.3.1}/myshell/paths.py +0 -0
- {myshell_py-0.2.0 → myshell_py-0.3.1}/myshell/progress.py +0 -0
- {myshell_py-0.2.0 → myshell_py-0.3.1}/myshell/quiz.py +0 -0
- {myshell_py-0.2.0 → myshell_py-0.3.1}/myshell/state.py +0 -0
- {myshell_py-0.2.0 → myshell_py-0.3.1}/pytest.ini +0 -0
- {myshell_py-0.2.0 → myshell_py-0.3.1}/shell.py +0 -0
- {myshell_py-0.2.0 → myshell_py-0.3.1}/src/myshell/__init__.py +0 -0
- {myshell_py-0.2.0 → myshell_py-0.3.1}/tests/test_aliases.py +0 -0
- {myshell_py-0.2.0 → myshell_py-0.3.1}/tests/test_arith.py +0 -0
- {myshell_py-0.2.0 → myshell_py-0.3.1}/tests/test_builtins.py +0 -0
- {myshell_py-0.2.0 → myshell_py-0.3.1}/tests/test_cli.py +0 -0
- {myshell_py-0.2.0 → myshell_py-0.3.1}/tests/test_completion.py +0 -0
- {myshell_py-0.2.0 → myshell_py-0.3.1}/tests/test_coreutils.py +0 -0
- {myshell_py-0.2.0 → myshell_py-0.3.1}/tests/test_expand.py +0 -0
- {myshell_py-0.2.0 → myshell_py-0.3.1}/tests/test_expansion_e2e.py +0 -0
- {myshell_py-0.2.0 → myshell_py-0.3.1}/tests/test_heredoc.py +0 -0
- {myshell_py-0.2.0 → myshell_py-0.3.1}/tests/test_highlight.py +0 -0
- {myshell_py-0.2.0 → myshell_py-0.3.1}/tests/test_history.py +0 -0
- {myshell_py-0.2.0 → myshell_py-0.3.1}/tests/test_history_fallback.py +0 -0
- {myshell_py-0.2.0 → myshell_py-0.3.1}/tests/test_if.py +0 -0
- {myshell_py-0.2.0 → myshell_py-0.3.1}/tests/test_interactive.py +0 -0
- {myshell_py-0.2.0 → myshell_py-0.3.1}/tests/test_jobs.py +0 -0
- {myshell_py-0.2.0 → myshell_py-0.3.1}/tests/test_language.py +0 -0
- {myshell_py-0.2.0 → myshell_py-0.3.1}/tests/test_lexer.py +0 -0
- {myshell_py-0.2.0 → myshell_py-0.3.1}/tests/test_loops.py +0 -0
- {myshell_py-0.2.0 → myshell_py-0.3.1}/tests/test_more_builtins.py +0 -0
- {myshell_py-0.2.0 → myshell_py-0.3.1}/tests/test_parser.py +0 -0
- {myshell_py-0.2.0 → myshell_py-0.3.1}/tests/test_pipelines.py +0 -0
- {myshell_py-0.2.0 → myshell_py-0.3.1}/tests/test_prompt.py +0 -0
- {myshell_py-0.2.0 → myshell_py-0.3.1}/tests/test_quiz_progress.py +0 -0
- {myshell_py-0.2.0 → myshell_py-0.3.1}/tests/test_redirects.py +0 -0
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.5
|
|
2
2
|
Name: myshell-py
|
|
3
|
-
Version: 0.
|
|
3
|
+
Version: 0.3.1
|
|
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
|
|
@@ -58,14 +58,12 @@ 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
|
-
|
|
62
61
|
- Pipes: `a | b`
|
|
63
62
|
- Lists: `a; b`, `a && b`, `a || b`
|
|
64
63
|
- Background jobs: `a &`
|
|
65
64
|
- Comments with `#`
|
|
66
65
|
|
|
67
66
|
Quoting and expansion
|
|
68
|
-
|
|
69
67
|
- Single quotes, double quotes and backslash escapes
|
|
70
68
|
- Variables: `$X`, `${X}`, `$?`, `$$`, and `$0 $1 ... $# $@ $*`
|
|
71
69
|
- 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 +74,12 @@ Quoting and expansion
|
|
|
76
74
|
- Assignments: `NAME=value`, and `NAME=value cmd` for one command
|
|
77
75
|
|
|
78
76
|
Redirection
|
|
79
|
-
|
|
80
77
|
- `< > >> 2> 2>> &> &>>`
|
|
81
78
|
- `2>&1` and `1>&2`, applied left to right
|
|
82
79
|
- Here-strings: `<<<`
|
|
83
80
|
- Here-documents: `<<EOF` and `<<-EOF`. A quoted delimiter such as `<<'EOF'` turns expansion off.
|
|
84
81
|
|
|
85
82
|
Control flow
|
|
86
|
-
|
|
87
83
|
- `if`, `elif`, `else`, `fi`
|
|
88
84
|
- `while`, `until`, `for NAME in WORDS`, with `do` and `done`. A bare `for x; do` loops over `"$@"`.
|
|
89
85
|
- `case WORD in a|b) ...;; *.txt) ...;; *) ...;; esac`
|
|
@@ -93,7 +89,6 @@ Control flow
|
|
|
93
89
|
- Blocks work on one line or across many lines
|
|
94
90
|
|
|
95
91
|
Builtins
|
|
96
|
-
|
|
97
92
|
- `echo` (with `-n -e -E`), `pwd cd exit alias unalias type which export unset source .`
|
|
98
93
|
- `read` (`-r -p -d -n`), `printf` (`-v`), `set` (`-e -u -x`, `-o`, `--`), `shift local return`
|
|
99
94
|
- `env` (`-i -u NAME=value`), `exec`, `trap` (EXIT, INT, TERM, HUP, USR1, USR2)
|
|
@@ -104,12 +99,10 @@ Builtins
|
|
|
104
99
|
- `guide`: lessons, cheat sheet and tips
|
|
105
100
|
|
|
106
101
|
Commands that work on every system
|
|
107
|
-
|
|
108
102
|
- `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.
|
|
109
103
|
- They also work in pipes and `$(...)` without fork. This is what makes Pip's lessons run on Windows.
|
|
110
104
|
|
|
111
105
|
Interactive use
|
|
112
|
-
|
|
113
106
|
- Job control: Ctrl+C, Ctrl+Z, `fg`, `bg`
|
|
114
107
|
- Tab completion for commands, paths and function names
|
|
115
108
|
- 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.
|
|
@@ -124,10 +117,9 @@ Interactive use
|
|
|
124
117
|
Pip is a small original character who lives in the shell.
|
|
125
118
|
|
|
126
119
|
,---. .--------------------------------------.
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
(_@_)>
|
|
120
|
+
( ^ ^ ) | Hi, I am Pip, your shell guide. |
|
|
121
|
+
\ v / '--------------------------------------'
|
|
122
|
+
(_@_)>
|
|
131
123
|
|
|
132
124
|
- Greets you at startup with a tip. Only on a real terminal.
|
|
133
125
|
- `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.
|
|
@@ -140,21 +132,31 @@ Pip is a small original character who lives in the shell.
|
|
|
140
132
|
|
|
141
133
|
## Prompt escapes
|
|
142
134
|
|
|
143
|
-
| Escape
|
|
144
|
-
|
|
|
145
|
-
| `\w`
|
|
146
|
-
| `\W`
|
|
147
|
-
| `\u` `\h`
|
|
148
|
-
| `\$`
|
|
149
|
-
| `\j`
|
|
150
|
-
| `\?`
|
|
151
|
-
| `\n` `\e` `\\`
|
|
152
|
-
| `\t` `\T` `\A` `\@` `\d` | time (24-hour, 12-hour, HH:MM, am/pm), date
|
|
153
|
-
| `\g`
|
|
154
|
-
| `\[` `\]`
|
|
135
|
+
| Escape | Meaning |
|
|
136
|
+
| --- | --- |
|
|
137
|
+
| `\w` | current directory, `~` for home |
|
|
138
|
+
| `\W` | last part of the directory |
|
|
139
|
+
| `\u` `\h` | user name, host name |
|
|
140
|
+
| `\$` | `$`, or `#` for root |
|
|
141
|
+
| `\j` | running jobs |
|
|
142
|
+
| `\?` | exit status of the last command |
|
|
143
|
+
| `\n` `\e` `\\` | newline, escape, backslash |
|
|
144
|
+
| `\t` `\T` `\A` `\@` `\d` | time (24-hour, 12-hour, HH:MM, am/pm), date |
|
|
145
|
+
| `\g` | git branch of the current folder, empty outside a repository |
|
|
146
|
+
| `\[` `\]` | wrap colors so line editing counts width correctly |
|
|
155
147
|
|
|
156
148
|
The default prompt adds the branch in brackets inside a git repository.
|
|
157
149
|
|
|
150
|
+
### Themes
|
|
151
|
+
|
|
152
|
+
A theme sets the colors of the default prompt, the syntax colors in the editor and Pip. Every theme except `default` and `mono` also colors the text you type and the text commands print.
|
|
153
|
+
|
|
154
|
+
theme list the themes with a preview
|
|
155
|
+
theme ocean switch and remember (saved in ~/.myshell_theme)
|
|
156
|
+
theme reset back to the default
|
|
157
|
+
|
|
158
|
+
Themes: `default`, `ocean`, `forest`, `sunset`, `light` (for a white background) and `mono` (no colors). `MYSHELL_THEME=ocean` picks one at start and wins over the saved choice. A `PS1` you set yourself keeps its own colors, and `NO_COLOR` turns colors off.
|
|
159
|
+
|
|
158
160
|
Example `~/.myshellrc`:
|
|
159
161
|
|
|
160
162
|
PS1='\u@\h \W \$ '
|
|
@@ -163,26 +165,27 @@ Example `~/.myshellrc`:
|
|
|
163
165
|
|
|
164
166
|
## Layout
|
|
165
167
|
|
|
166
|
-
| File
|
|
167
|
-
|
|
|
168
|
-
| `cli.py`
|
|
169
|
-
| `lexer.py`
|
|
170
|
-
| `parser.py`
|
|
171
|
-
| `expand.py`
|
|
172
|
-
| `arith.py`
|
|
173
|
-
| `heredoc.py`
|
|
174
|
-
| `executor.py`
|
|
175
|
-
| `jobs.py`
|
|
176
|
-
| `builtins.py`
|
|
177
|
-
| `more_builtins.py`
|
|
178
|
-
| `coreutils.py`
|
|
179
|
-
| `editor.py` `highlight.py` | optional prompt_toolkit line editor and syntax colors
|
|
180
|
-
| `progress.py` `quiz.py`
|
|
181
|
-
| `completion.py`
|
|
182
|
-
| `prompt.py`
|
|
183
|
-
| `
|
|
184
|
-
| `
|
|
185
|
-
| `
|
|
168
|
+
| File | Job |
|
|
169
|
+
| --- | --- |
|
|
170
|
+
| `cli.py` | entry point, interactive loop |
|
|
171
|
+
| `lexer.py` | text to tokens |
|
|
172
|
+
| `parser.py` | tokens to a tree |
|
|
173
|
+
| `expand.py` | variables, substitution, math, globbing |
|
|
174
|
+
| `arith.py` | the `$((...))` evaluator |
|
|
175
|
+
| `heredoc.py` | here-document bodies |
|
|
176
|
+
| `executor.py` | runs the tree with fork and pipes |
|
|
177
|
+
| `jobs.py` | process groups and job control |
|
|
178
|
+
| `builtins.py` | core builtin commands, lookup of builtins |
|
|
179
|
+
| `more_builtins.py` | read, printf, set, env, which, trap, exec and friends |
|
|
180
|
+
| `coreutils.py` | ls, cat, head, tr, sleep, mkdir, rm, cp, mv, touch, wc, grep |
|
|
181
|
+
| `editor.py` `highlight.py` | optional prompt_toolkit line editor and syntax colors |
|
|
182
|
+
| `progress.py` `quiz.py` | Pip's progress file and quiz questions |
|
|
183
|
+
| `completion.py` | tab completion |
|
|
184
|
+
| `prompt.py` | prompt escapes |
|
|
185
|
+
| `theme.py` | color themes |
|
|
186
|
+
| `guide.py` | Pip: lessons, hints, greeting |
|
|
187
|
+
| `state.py` | variables, aliases, history, status |
|
|
188
|
+
| `compat.py` | platform checks |
|
|
186
189
|
|
|
187
190
|
## Limits
|
|
188
191
|
|
|
@@ -42,14 +42,12 @@ 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
|
-
|
|
46
45
|
- Pipes: `a | b`
|
|
47
46
|
- Lists: `a; b`, `a && b`, `a || b`
|
|
48
47
|
- Background jobs: `a &`
|
|
49
48
|
- Comments with `#`
|
|
50
49
|
|
|
51
50
|
Quoting and expansion
|
|
52
|
-
|
|
53
51
|
- Single quotes, double quotes and backslash escapes
|
|
54
52
|
- Variables: `$X`, `${X}`, `$?`, `$$`, and `$0 $1 ... $# $@ $*`
|
|
55
53
|
- 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 +58,12 @@ Quoting and expansion
|
|
|
60
58
|
- Assignments: `NAME=value`, and `NAME=value cmd` for one command
|
|
61
59
|
|
|
62
60
|
Redirection
|
|
63
|
-
|
|
64
61
|
- `< > >> 2> 2>> &> &>>`
|
|
65
62
|
- `2>&1` and `1>&2`, applied left to right
|
|
66
63
|
- Here-strings: `<<<`
|
|
67
64
|
- Here-documents: `<<EOF` and `<<-EOF`. A quoted delimiter such as `<<'EOF'` turns expansion off.
|
|
68
65
|
|
|
69
66
|
Control flow
|
|
70
|
-
|
|
71
67
|
- `if`, `elif`, `else`, `fi`
|
|
72
68
|
- `while`, `until`, `for NAME in WORDS`, with `do` and `done`. A bare `for x; do` loops over `"$@"`.
|
|
73
69
|
- `case WORD in a|b) ...;; *.txt) ...;; *) ...;; esac`
|
|
@@ -77,7 +73,6 @@ Control flow
|
|
|
77
73
|
- Blocks work on one line or across many lines
|
|
78
74
|
|
|
79
75
|
Builtins
|
|
80
|
-
|
|
81
76
|
- `echo` (with `-n -e -E`), `pwd cd exit alias unalias type which export unset source .`
|
|
82
77
|
- `read` (`-r -p -d -n`), `printf` (`-v`), `set` (`-e -u -x`, `-o`, `--`), `shift local return`
|
|
83
78
|
- `env` (`-i -u NAME=value`), `exec`, `trap` (EXIT, INT, TERM, HUP, USR1, USR2)
|
|
@@ -88,12 +83,10 @@ Builtins
|
|
|
88
83
|
- `guide`: lessons, cheat sheet and tips
|
|
89
84
|
|
|
90
85
|
Commands that work on every system
|
|
91
|
-
|
|
92
86
|
- `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.
|
|
93
87
|
- They also work in pipes and `$(...)` without fork. This is what makes Pip's lessons run on Windows.
|
|
94
88
|
|
|
95
89
|
Interactive use
|
|
96
|
-
|
|
97
90
|
- Job control: Ctrl+C, Ctrl+Z, `fg`, `bg`
|
|
98
91
|
- Tab completion for commands, paths and function names
|
|
99
92
|
- 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.
|
|
@@ -108,10 +101,9 @@ Interactive use
|
|
|
108
101
|
Pip is a small original character who lives in the shell.
|
|
109
102
|
|
|
110
103
|
,---. .--------------------------------------.
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
(_@_)>
|
|
104
|
+
( ^ ^ ) | Hi, I am Pip, your shell guide. |
|
|
105
|
+
\ v / '--------------------------------------'
|
|
106
|
+
(_@_)>
|
|
115
107
|
|
|
116
108
|
- Greets you at startup with a tip. Only on a real terminal.
|
|
117
109
|
- `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.
|
|
@@ -124,21 +116,31 @@ Pip is a small original character who lives in the shell.
|
|
|
124
116
|
|
|
125
117
|
## Prompt escapes
|
|
126
118
|
|
|
127
|
-
| Escape
|
|
128
|
-
|
|
|
129
|
-
| `\w`
|
|
130
|
-
| `\W`
|
|
131
|
-
| `\u` `\h`
|
|
132
|
-
| `\$`
|
|
133
|
-
| `\j`
|
|
134
|
-
| `\?`
|
|
135
|
-
| `\n` `\e` `\\`
|
|
136
|
-
| `\t` `\T` `\A` `\@` `\d` | time (24-hour, 12-hour, HH:MM, am/pm), date
|
|
137
|
-
| `\g`
|
|
138
|
-
| `\[` `\]`
|
|
119
|
+
| Escape | Meaning |
|
|
120
|
+
| --- | --- |
|
|
121
|
+
| `\w` | current directory, `~` for home |
|
|
122
|
+
| `\W` | last part of the directory |
|
|
123
|
+
| `\u` `\h` | user name, host name |
|
|
124
|
+
| `\$` | `$`, or `#` for root |
|
|
125
|
+
| `\j` | running jobs |
|
|
126
|
+
| `\?` | exit status of the last command |
|
|
127
|
+
| `\n` `\e` `\\` | newline, escape, backslash |
|
|
128
|
+
| `\t` `\T` `\A` `\@` `\d` | time (24-hour, 12-hour, HH:MM, am/pm), date |
|
|
129
|
+
| `\g` | git branch of the current folder, empty outside a repository |
|
|
130
|
+
| `\[` `\]` | wrap colors so line editing counts width correctly |
|
|
139
131
|
|
|
140
132
|
The default prompt adds the branch in brackets inside a git repository.
|
|
141
133
|
|
|
134
|
+
### Themes
|
|
135
|
+
|
|
136
|
+
A theme sets the colors of the default prompt, the syntax colors in the editor and Pip. Every theme except `default` and `mono` also colors the text you type and the text commands print.
|
|
137
|
+
|
|
138
|
+
theme list the themes with a preview
|
|
139
|
+
theme ocean switch and remember (saved in ~/.myshell_theme)
|
|
140
|
+
theme reset back to the default
|
|
141
|
+
|
|
142
|
+
Themes: `default`, `ocean`, `forest`, `sunset`, `light` (for a white background) and `mono` (no colors). `MYSHELL_THEME=ocean` picks one at start and wins over the saved choice. A `PS1` you set yourself keeps its own colors, and `NO_COLOR` turns colors off.
|
|
143
|
+
|
|
142
144
|
Example `~/.myshellrc`:
|
|
143
145
|
|
|
144
146
|
PS1='\u@\h \W \$ '
|
|
@@ -147,26 +149,27 @@ Example `~/.myshellrc`:
|
|
|
147
149
|
|
|
148
150
|
## Layout
|
|
149
151
|
|
|
150
|
-
| File
|
|
151
|
-
|
|
|
152
|
-
| `cli.py`
|
|
153
|
-
| `lexer.py`
|
|
154
|
-
| `parser.py`
|
|
155
|
-
| `expand.py`
|
|
156
|
-
| `arith.py`
|
|
157
|
-
| `heredoc.py`
|
|
158
|
-
| `executor.py`
|
|
159
|
-
| `jobs.py`
|
|
160
|
-
| `builtins.py`
|
|
161
|
-
| `more_builtins.py`
|
|
162
|
-
| `coreutils.py`
|
|
163
|
-
| `editor.py` `highlight.py` | optional prompt_toolkit line editor and syntax colors
|
|
164
|
-
| `progress.py` `quiz.py`
|
|
165
|
-
| `completion.py`
|
|
166
|
-
| `prompt.py`
|
|
167
|
-
| `
|
|
168
|
-
| `
|
|
169
|
-
| `
|
|
152
|
+
| File | Job |
|
|
153
|
+
| --- | --- |
|
|
154
|
+
| `cli.py` | entry point, interactive loop |
|
|
155
|
+
| `lexer.py` | text to tokens |
|
|
156
|
+
| `parser.py` | tokens to a tree |
|
|
157
|
+
| `expand.py` | variables, substitution, math, globbing |
|
|
158
|
+
| `arith.py` | the `$((...))` evaluator |
|
|
159
|
+
| `heredoc.py` | here-document bodies |
|
|
160
|
+
| `executor.py` | runs the tree with fork and pipes |
|
|
161
|
+
| `jobs.py` | process groups and job control |
|
|
162
|
+
| `builtins.py` | core builtin commands, lookup of builtins |
|
|
163
|
+
| `more_builtins.py` | read, printf, set, env, which, trap, exec and friends |
|
|
164
|
+
| `coreutils.py` | ls, cat, head, tr, sleep, mkdir, rm, cp, mv, touch, wc, grep |
|
|
165
|
+
| `editor.py` `highlight.py` | optional prompt_toolkit line editor and syntax colors |
|
|
166
|
+
| `progress.py` `quiz.py` | Pip's progress file and quiz questions |
|
|
167
|
+
| `completion.py` | tab completion |
|
|
168
|
+
| `prompt.py` | prompt escapes |
|
|
169
|
+
| `theme.py` | color themes |
|
|
170
|
+
| `guide.py` | Pip: lessons, hints, greeting |
|
|
171
|
+
| `state.py` | variables, aliases, history, status |
|
|
172
|
+
| `compat.py` | platform checks |
|
|
170
173
|
|
|
171
174
|
## Limits
|
|
172
175
|
|
|
@@ -16,6 +16,7 @@ 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
20
|
from .prompt import build_continuation_prompt, build_prompt, slow_notice
|
|
20
21
|
from .state import ShellState
|
|
21
22
|
|
|
@@ -98,6 +99,10 @@ def run_interactive(state: ShellState) -> int:
|
|
|
98
99
|
except EOFError:
|
|
99
100
|
return None
|
|
100
101
|
state.missing_command = None
|
|
102
|
+
tint = theme.text_start() if interactive else ""
|
|
103
|
+
if tint:
|
|
104
|
+
sys.stdout.write(tint) # the theme's text color covers what the command prints
|
|
105
|
+
sys.stdout.flush()
|
|
101
106
|
started = time.monotonic()
|
|
102
107
|
try:
|
|
103
108
|
state.execute(line, read_more)
|
|
@@ -111,6 +116,9 @@ def run_interactive(state: ShellState) -> int:
|
|
|
111
116
|
except KeyboardInterrupt:
|
|
112
117
|
print()
|
|
113
118
|
state.last_duration = time.monotonic() - started
|
|
119
|
+
if tint:
|
|
120
|
+
sys.stdout.write("\x1b[0m")
|
|
121
|
+
sys.stdout.flush()
|
|
114
122
|
if interactive:
|
|
115
123
|
state.save_history() # saved after every line, so a killed shell loses nothing
|
|
116
124
|
if state.pending_traps:
|
|
@@ -44,6 +44,9 @@ class Completer:
|
|
|
44
44
|
if text.startswith("$"):
|
|
45
45
|
return self.variable_matches(text)
|
|
46
46
|
before = before.rstrip()
|
|
47
|
+
if before == "theme":
|
|
48
|
+
from . import theme
|
|
49
|
+
return sorted(n for n in theme.names() + ["reset"] if n.startswith(text))
|
|
47
50
|
at_command = (before == "" or (before.endswith(COMMAND_PREFIXES)
|
|
48
51
|
and not before.endswith(">")))
|
|
49
52
|
if at_command and "/" not in text and not text.startswith("~"):
|
|
@@ -9,7 +9,8 @@ from typing import Any, Callable, Dict, List, Optional, Tuple
|
|
|
9
9
|
|
|
10
10
|
from . import history
|
|
11
11
|
from .completion import complete_line
|
|
12
|
-
from .
|
|
12
|
+
from . import theme
|
|
13
|
+
from .highlight import tokenize_for_color
|
|
13
14
|
from .state import ShellState
|
|
14
15
|
|
|
15
16
|
SUGGESTION_STYLE = "fg:#888888"
|
|
@@ -70,7 +71,7 @@ def _build(state: ShellState, input: Any, output: Any) -> Any:
|
|
|
70
71
|
from prompt_toolkit.history import History
|
|
71
72
|
from prompt_toolkit.lexers import Lexer
|
|
72
73
|
from prompt_toolkit.shortcuts import CompleteStyle
|
|
73
|
-
from prompt_toolkit.styles import Style
|
|
74
|
+
from prompt_toolkit.styles import DynamicStyle, Style
|
|
74
75
|
|
|
75
76
|
class ShellHistory(History):
|
|
76
77
|
"""The shell's own history list, newest first. Lines are added by the shell."""
|
|
@@ -148,7 +149,10 @@ def _build(state: ShellState, input: Any, output: Any) -> Any:
|
|
|
148
149
|
|
|
149
150
|
bindings.add("right", filter=at_end_without_suggestion)(accept_now)
|
|
150
151
|
bindings.add("end", filter=at_end_without_suggestion)(accept_now)
|
|
151
|
-
|
|
152
|
+
def current_style() -> Any:
|
|
153
|
+
t = theme.active()
|
|
154
|
+
return Style.from_dict(dict(t.syntax, **{"auto-suggestion": t.suggestion or SUGGESTION_STYLE}))
|
|
155
|
+
style = DynamicStyle(current_style)
|
|
152
156
|
kwargs: Dict[str, Any] = {}
|
|
153
157
|
if input is not None:
|
|
154
158
|
kwargs["input"] = input
|
|
@@ -22,7 +22,7 @@ from dataclasses import dataclass, field
|
|
|
22
22
|
from pathlib import Path
|
|
23
23
|
from typing import Callable, List, Optional, TextIO
|
|
24
24
|
|
|
25
|
-
from . import compat, history, progress, quiz
|
|
25
|
+
from . import compat, history, progress, quiz, theme
|
|
26
26
|
from .state import ShellState
|
|
27
27
|
|
|
28
28
|
# --- the character ---------------------------------------------------------
|
|
@@ -40,7 +40,7 @@ MOODS = { # mood: (eyes, mouth)
|
|
|
40
40
|
"wow": ("* *", "O"),
|
|
41
41
|
}
|
|
42
42
|
ART_WIDTH = 7
|
|
43
|
-
|
|
43
|
+
RESET = "\x1b[0m"
|
|
44
44
|
|
|
45
45
|
|
|
46
46
|
def pip_lines(mood: str = "happy") -> List[str]:
|
|
@@ -61,8 +61,7 @@ def bubble(text: str, width: int) -> List[str]:
|
|
|
61
61
|
|
|
62
62
|
|
|
63
63
|
def use_color(out: TextIO) -> bool:
|
|
64
|
-
return
|
|
65
|
-
and os.environ.get("TERM", "") not in ("", "dumb"))
|
|
64
|
+
return hasattr(out, "isatty") and out.isatty() and theme.terminal_colors()
|
|
66
65
|
|
|
67
66
|
|
|
68
67
|
def render(text: str, mood: str = "happy", color: bool = False, columns: int = 80) -> str:
|
|
@@ -75,7 +74,9 @@ def render(text: str, mood: str = "happy", color: bool = False, columns: int = 8
|
|
|
75
74
|
for i in range(rows):
|
|
76
75
|
face = art[i] if i < len(art) else " " * ART_WIDTH
|
|
77
76
|
if color and i < len(art):
|
|
78
|
-
|
|
77
|
+
active = theme.active()
|
|
78
|
+
if active.colorful:
|
|
79
|
+
face = active.sgr(active.pip) + face + theme.text_reset()
|
|
79
80
|
out.append(f"{face} {box[i] if i < len(box) else ''}".rstrip())
|
|
80
81
|
return "\n".join(out)
|
|
81
82
|
|
|
@@ -283,7 +284,7 @@ Case case $X in a|b) cmds;; *.txt) cmds;; *) cmds;; esac
|
|
|
283
284
|
Loops for X in a b; do ..; done while C; do ..; done until C; do ..; done
|
|
284
285
|
Loop control break continue break 2
|
|
285
286
|
Jobs cmd & jobs fg bg wait Ctrl+C Ctrl+Z
|
|
286
|
-
Builtins cd pwd echo printf read alias unalias type which export unset set env
|
|
287
|
+
Builtins cd pwd echo printf read alias unalias type which export unset set env theme
|
|
287
288
|
source exec trap shift local history true false : exit
|
|
288
289
|
Files and text ls cat head tr wc grep touch mkdir rm cp mv sleep
|
|
289
290
|
Set options set -e (stop on error) set -u (unset is error) set -x (trace)
|
|
@@ -6,6 +6,9 @@ import shutil
|
|
|
6
6
|
import signal
|
|
7
7
|
from typing import Callable, Dict, List, Optional, TextIO
|
|
8
8
|
|
|
9
|
+
import difflib
|
|
10
|
+
|
|
11
|
+
from . import theme
|
|
9
12
|
from .errors import ReturnFromFunction, ShellExit
|
|
10
13
|
from .state import ShellState
|
|
11
14
|
|
|
@@ -526,7 +529,47 @@ def builtin_trap(state: ShellState, args: List[str], stdout: TextIO, stderr: Tex
|
|
|
526
529
|
return status
|
|
527
530
|
|
|
528
531
|
|
|
532
|
+
def builtin_theme(state: ShellState, args: List[str], stdout: TextIO, stderr: TextIO) -> int:
|
|
533
|
+
"""theme: list the themes. theme NAME: switch and remember. theme reset: back to default."""
|
|
534
|
+
color = hasattr(stdout, "isatty") and stdout.isatty() and theme.terminal_colors()
|
|
535
|
+
if args and args[0] in ("-h", "--help"):
|
|
536
|
+
print("usage: theme [NAME | reset]\n theme list the themes\n"
|
|
537
|
+
" theme NAME use a theme and remember it\n theme reset go back to the default",
|
|
538
|
+
file=stdout)
|
|
539
|
+
return 0
|
|
540
|
+
if not args:
|
|
541
|
+
now = theme.active().name
|
|
542
|
+
for t in theme.THEMES.values():
|
|
543
|
+
mark = "*" if t.name == now else " "
|
|
544
|
+
print(f"{mark} {t.name:<8} {theme.sample(t, color)} {t.about}", file=stdout)
|
|
545
|
+
if hasattr(stdout, "isatty") and stdout.isatty():
|
|
546
|
+
why = theme.colors_off_reason()
|
|
547
|
+
if why:
|
|
548
|
+
print(f"Colors are off: {why}.", file=stdout)
|
|
549
|
+
if os.environ.get("MYSHELL_THEME"):
|
|
550
|
+
print(f"MYSHELL_THEME={os.environ['MYSHELL_THEME']} sets the theme at start.", file=stdout)
|
|
551
|
+
return 0
|
|
552
|
+
if len(args) > 1:
|
|
553
|
+
print("theme: too many arguments", file=stderr)
|
|
554
|
+
return 2
|
|
555
|
+
name = theme.DEFAULT if args[0] == "reset" else args[0].lower()
|
|
556
|
+
if name not in theme.THEMES:
|
|
557
|
+
close = difflib.get_close_matches(name, theme.names(), n=1)
|
|
558
|
+
hint = f" Did you mean '{close[0]}'?" if close else ""
|
|
559
|
+
print(f"theme: unknown theme '{args[0]}'.{hint} Run theme to see the list.", file=stderr)
|
|
560
|
+
return 1
|
|
561
|
+
chosen = theme.select(name)
|
|
562
|
+
if color:
|
|
563
|
+
stdout.write(theme.text_start()) # the message already shows the new text color
|
|
564
|
+
print(f"Theme: {name}", file=stdout)
|
|
565
|
+
why = theme.colors_off_reason(chosen) if name != "mono" else ""
|
|
566
|
+
if why and hasattr(stdout, "isatty") and stdout.isatty():
|
|
567
|
+
print(f"Colors are off: {why}.", file=stdout)
|
|
568
|
+
return 0
|
|
569
|
+
|
|
570
|
+
|
|
529
571
|
EXTRA_BUILTINS: Dict[str, Builtin] = {
|
|
572
|
+
"theme": builtin_theme,
|
|
530
573
|
"true": builtin_true,
|
|
531
574
|
"false": builtin_false,
|
|
532
575
|
":": builtin_true,
|
|
@@ -6,6 +6,7 @@ import sys
|
|
|
6
6
|
import time
|
|
7
7
|
from typing import List, Optional
|
|
8
8
|
|
|
9
|
+
from . import theme
|
|
9
10
|
from .state import ShellState
|
|
10
11
|
|
|
11
12
|
try:
|
|
@@ -13,7 +14,7 @@ try:
|
|
|
13
14
|
# The libedit on macOS prints the text between \x01 and \x02 out of order, so no markers there.
|
|
14
15
|
MARKERS = not (sys.platform == "darwin" and "libedit" in (_readline.__doc__ or ""))
|
|
15
16
|
except ImportError:
|
|
16
|
-
MARKERS =
|
|
17
|
+
MARKERS = False # without readline, input() would print the markers
|
|
17
18
|
|
|
18
19
|
|
|
19
20
|
# Prompt
|
|
@@ -184,14 +185,18 @@ def build_prompt(state: ShellState) -> str:
|
|
|
184
185
|
custom = state.get_variable("PS1")
|
|
185
186
|
if custom is not None:
|
|
186
187
|
return expand_prompt(custom, state)
|
|
187
|
-
|
|
188
|
-
|
|
188
|
+
th = theme.active()
|
|
189
|
+
color = th.colorful and theme.terminal_colors()
|
|
190
|
+
back = (r"\[\e[0m\]" + (r"\[\e[" + th.text + r"m\]" if th.text else "")) if color else ""
|
|
191
|
+
template = (r"\[\e[" + th.dir + r"m\]\w" + back + r" \$ ") if color else DEFAULT_PS1_PLAIN
|
|
192
|
+
tail = (r"\[\e[" + th.text + r"m\]") if color and th.text else ""
|
|
189
193
|
branch = git_branch()
|
|
190
194
|
if branch:
|
|
191
195
|
# The branch name goes in as plain text. A backslash in it must not act as an escape.
|
|
192
196
|
safe = branch.replace("\\", "\\\\")
|
|
193
|
-
shown = (r"\[\e[
|
|
197
|
+
shown = (r"\[\e[" + th.branch + r"m\](" + safe + ")" + back) if color else "(" + safe + ")"
|
|
194
198
|
template = template.replace(r" \$ ", " " + shown + r" \$ ")
|
|
195
199
|
if state.last_status != 0:
|
|
196
|
-
|
|
197
|
-
|
|
200
|
+
failed = (r"\[\e[" + th.fail + r"m\][\?]" + back + " ") if color else FAILED_PREFIX_PLAIN
|
|
201
|
+
template = failed + template
|
|
202
|
+
return expand_prompt(template + tail, state)
|