xmyshell 0.2.22__tar.gz → 0.2.23__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.
- {xmyshell-0.2.22/xmyshell.egg-info → xmyshell-0.2.23}/PKG-INFO +279 -22
- {xmyshell-0.2.22 → xmyshell-0.2.23}/README.md +278 -21
- {xmyshell-0.2.22 → xmyshell-0.2.23}/pyproject.toml +1 -1
- {xmyshell-0.2.22 → xmyshell-0.2.23}/xmyshell/kernel.py +9 -4
- {xmyshell-0.2.22 → xmyshell-0.2.23}/xmyshell/keybindings.py +2 -2
- {xmyshell-0.2.22 → xmyshell-0.2.23/xmyshell.egg-info}/PKG-INFO +279 -22
- {xmyshell-0.2.22 → xmyshell-0.2.23}/LICENSE +0 -0
- {xmyshell-0.2.22 → xmyshell-0.2.23}/setup.cfg +0 -0
- {xmyshell-0.2.22 → xmyshell-0.2.23}/xmyshell/__init__.py +0 -0
- {xmyshell-0.2.22 → xmyshell-0.2.23}/xmyshell/__main__.py +0 -0
- {xmyshell-0.2.22 → xmyshell-0.2.23}/xmyshell/completer.py +0 -0
- {xmyshell-0.2.22 → xmyshell-0.2.23}/xmyshell/data/commands.json +0 -0
- {xmyshell-0.2.22 → xmyshell-0.2.23}/xmyshell/environment.py +0 -0
- {xmyshell-0.2.22 → xmyshell-0.2.23}/xmyshell/init.py +0 -0
- {xmyshell-0.2.22 → xmyshell-0.2.23}/xmyshell/injection.py +0 -0
- {xmyshell-0.2.22 → xmyshell-0.2.23}/xmyshell/main.py +0 -0
- {xmyshell-0.2.22 → xmyshell-0.2.23}/xmyshell/meta.py +0 -0
- {xmyshell-0.2.22 → xmyshell-0.2.23}/xmyshell/stubs/__init__.py +0 -0
- {xmyshell-0.2.22 → xmyshell-0.2.23}/xmyshell/stubs/__init__.pyi +0 -0
- {xmyshell-0.2.22 → xmyshell-0.2.23}/xmyshell/stubs/py.typed +0 -0
- {xmyshell-0.2.22 → xmyshell-0.2.23}/xmyshell/themes.py +0 -0
- {xmyshell-0.2.22 → xmyshell-0.2.23}/xmyshell/update.py +0 -0
- {xmyshell-0.2.22 → xmyshell-0.2.23}/xmyshell/utils.py +0 -0
- {xmyshell-0.2.22 → xmyshell-0.2.23}/xmyshell.egg-info/SOURCES.txt +0 -0
- {xmyshell-0.2.22 → xmyshell-0.2.23}/xmyshell.egg-info/dependency_links.txt +0 -0
- {xmyshell-0.2.22 → xmyshell-0.2.23}/xmyshell.egg-info/entry_points.txt +0 -0
- {xmyshell-0.2.22 → xmyshell-0.2.23}/xmyshell.egg-info/requires.txt +0 -0
- {xmyshell-0.2.22 → xmyshell-0.2.23}/xmyshell.egg-info/top_level.txt +0 -0
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.4
|
|
2
2
|
Name: xmyshell
|
|
3
|
-
Version: 0.2.
|
|
3
|
+
Version: 0.2.23
|
|
4
4
|
Summary: XmyShell is a shell-like tool built on top of prompt_toolkit which provides a persistent Python runtime.
|
|
5
5
|
Requires-Python: >=3.12
|
|
6
6
|
Description-Content-Type: text/markdown
|
|
@@ -39,27 +39,27 @@ Username@hostname ➜ ~ 0ms
|
|
|
39
39
|
|
|
40
40
|
- Persistent Python namespace across commands (variables, imports, functions)
|
|
41
41
|
- Expand inline Python expressions within `{}`, using independent namespace.
|
|
42
|
-
```
|
|
42
|
+
```bash
|
|
43
43
|
❯ mkdir {" ".join(f"test{i}" for i in range(10))}
|
|
44
44
|
❯ ls
|
|
45
45
|
test0 test1 test2 test3 test4 test5 test6 test7 test8 test9
|
|
46
46
|
```
|
|
47
47
|
|
|
48
48
|
- Evaluate and print Python expressions with `print`
|
|
49
|
-
```
|
|
49
|
+
```bash
|
|
50
50
|
❯ print 1 + 1
|
|
51
51
|
2
|
|
52
52
|
```
|
|
53
53
|
|
|
54
54
|
- Execute Python statements with `pyexec`
|
|
55
|
-
```
|
|
55
|
+
```bash
|
|
56
56
|
❯ pyexec files = [f for f in os.listdir('.') if f.endswith('.py')]
|
|
57
57
|
❯ print len(files)
|
|
58
58
|
3
|
|
59
59
|
```
|
|
60
60
|
|
|
61
61
|
- Capture command output into a Python variable with `=>`.
|
|
62
|
-
```
|
|
62
|
+
```bash
|
|
63
63
|
❯ which python => path
|
|
64
64
|
❯ print path
|
|
65
65
|
/usr/bin/python
|
|
@@ -69,14 +69,14 @@ test0 test1 test2 test3 test4 test5 test6 test7 test8 test9
|
|
|
69
69
|
```
|
|
70
70
|
|
|
71
71
|
- Redirect the output of Python commands (`print`, `pyexec`) with `|>`
|
|
72
|
-
```
|
|
72
|
+
```bash
|
|
73
73
|
❯ print "\n".join(str(i) for i in range(100)) |> grep 42 => result
|
|
74
74
|
❯ print result
|
|
75
75
|
42
|
|
76
76
|
```
|
|
77
77
|
|
|
78
78
|
- Built-in `source` command to run python scripts.
|
|
79
|
-
```
|
|
79
|
+
```bash
|
|
80
80
|
❯ which python
|
|
81
81
|
/usr/bin/python
|
|
82
82
|
❯ source .venv/bin/activate_this.py
|
|
@@ -85,7 +85,7 @@ test0 test1 test2 test3 test4 test5 test6 test7 test8 test9
|
|
|
85
85
|
```
|
|
86
86
|
|
|
87
87
|
- Built-in `export` command.
|
|
88
|
-
```
|
|
88
|
+
```bash
|
|
89
89
|
❯ pyexec foo = "foo"
|
|
90
90
|
❯ export ENV_VAR={foo}bar
|
|
91
91
|
❯ print ENV_VAR
|
|
@@ -93,27 +93,27 @@ foobar
|
|
|
93
93
|
```
|
|
94
94
|
|
|
95
95
|
- Built-in `import` command.
|
|
96
|
-
```
|
|
96
|
+
```bash
|
|
97
97
|
❯ import numpy as np
|
|
98
98
|
❯ from math import *
|
|
99
99
|
```
|
|
100
100
|
|
|
101
101
|
- Reload with `reload` command.
|
|
102
|
-
```
|
|
102
|
+
```bash
|
|
103
103
|
❯ reload
|
|
104
104
|
```
|
|
105
105
|
|
|
106
106
|
- Update xmyshell (optionally to a specific version).
|
|
107
|
-
```
|
|
107
|
+
```bash
|
|
108
108
|
❯ udpate
|
|
109
109
|
```
|
|
110
110
|
or
|
|
111
|
-
```
|
|
111
|
+
```bash
|
|
112
112
|
❯ update 0.1.3
|
|
113
113
|
```
|
|
114
114
|
|
|
115
115
|
- Alias
|
|
116
|
-
```
|
|
116
|
+
```bash
|
|
117
117
|
❯ alias ll='ls -lh'
|
|
118
118
|
❯ unalias ll
|
|
119
119
|
```
|
|
@@ -122,17 +122,16 @@ or
|
|
|
122
122
|
E.g. `{["arg1", "arg2 xxx"]}` will be expanded into `arg1 'arg2 xxx'`
|
|
123
123
|
|
|
124
124
|
Here is an example (though there are other ways to do this, it is just an example )
|
|
125
|
-
```
|
|
125
|
+
```bash
|
|
126
126
|
❯ pip install {cat("requirements.txt").splitlines()}
|
|
127
127
|
```
|
|
128
128
|
|
|
129
129
|
- Multiline input with ending `\`.
|
|
130
|
-
```
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
[~] $ pyexec foo()
|
|
130
|
+
```python
|
|
131
|
+
❯ pyexec
|
|
132
|
+
def foo():
|
|
133
|
+
print("Hello!")
|
|
134
|
+
❯ pyexec foo()
|
|
136
135
|
Hello!
|
|
137
136
|
```
|
|
138
137
|
|
|
@@ -211,6 +210,266 @@ from xmyshell.themes import ... # themes
|
|
|
211
210
|
from xmyshell.stubs import ... # stubs for built-in names
|
|
212
211
|
```
|
|
213
212
|
|
|
213
|
+
## Examples / Bash Equivalents
|
|
214
|
+
|
|
215
|
+
Here are some equivalent forms of common Bash patterns.
|
|
216
|
+
|
|
217
|
+
### Capture command output into a variable
|
|
218
|
+
|
|
219
|
+
Bash:
|
|
220
|
+
```bash
|
|
221
|
+
python_path=$(which python)
|
|
222
|
+
echo "Python is at $python_path"
|
|
223
|
+
```
|
|
224
|
+
|
|
225
|
+
XmyShell:
|
|
226
|
+
```bash
|
|
227
|
+
which python => python_path
|
|
228
|
+
print "Python is at " + python_path
|
|
229
|
+
```
|
|
230
|
+
|
|
231
|
+
### Expand file contents into command arguments
|
|
232
|
+
|
|
233
|
+
Bash:
|
|
234
|
+
```bash
|
|
235
|
+
pip install $(cat requirements.txt)
|
|
236
|
+
```
|
|
237
|
+
|
|
238
|
+
XmyShell:
|
|
239
|
+
```bash
|
|
240
|
+
pip install {cat("requirements.txt").splitlines()}
|
|
241
|
+
```
|
|
242
|
+
|
|
243
|
+
`cat()` is a built-in XmyShell helper equivalent to `open(file).read()`. The list returned by `splitlines()` is expanded into separate shell arguments.
|
|
244
|
+
|
|
245
|
+
### Brace expansion / sequence expansion
|
|
246
|
+
|
|
247
|
+
Bash:
|
|
248
|
+
```bash
|
|
249
|
+
echo {0..4}
|
|
250
|
+
```
|
|
251
|
+
|
|
252
|
+
XmyShell:
|
|
253
|
+
```bash
|
|
254
|
+
echo {range(5)}
|
|
255
|
+
```
|
|
256
|
+
|
|
257
|
+
Bash:
|
|
258
|
+
```bash
|
|
259
|
+
touch file{0..4}
|
|
260
|
+
```
|
|
261
|
+
|
|
262
|
+
XmyShell:
|
|
263
|
+
```bash
|
|
264
|
+
touch {f"file{i}" for i in range(5)}
|
|
265
|
+
```
|
|
266
|
+
|
|
267
|
+
Bash:
|
|
268
|
+
```bash
|
|
269
|
+
mkdir test{0..9}
|
|
270
|
+
```
|
|
271
|
+
|
|
272
|
+
XmyShell:
|
|
273
|
+
```bash
|
|
274
|
+
mkdir {f"test{i}" for i in range(10)}
|
|
275
|
+
```
|
|
276
|
+
|
|
277
|
+
Lists, tuples, generators, and similar iterables are expanded into separate shell arguments.
|
|
278
|
+
|
|
279
|
+
### Python expressions and statements
|
|
280
|
+
|
|
281
|
+
Bash:
|
|
282
|
+
```bash
|
|
283
|
+
python -c 'print(1 + 1)'
|
|
284
|
+
```
|
|
285
|
+
|
|
286
|
+
XmyShell:
|
|
287
|
+
```bash
|
|
288
|
+
print 1 + 1
|
|
289
|
+
```
|
|
290
|
+
|
|
291
|
+
Bash:
|
|
292
|
+
```bash
|
|
293
|
+
python -c 'files=[f for f in __import__("os").listdir(".") if f.endswith(".py")]; print(len(files))'
|
|
294
|
+
```
|
|
295
|
+
|
|
296
|
+
XmyShell:
|
|
297
|
+
```bash
|
|
298
|
+
pyexec files = [f for f in os.listdir(".") if f.endswith(".py")]
|
|
299
|
+
print len(files)
|
|
300
|
+
```
|
|
301
|
+
|
|
302
|
+
`pyexec` executes Python statements and keeps them in the persistent Python namespace.
|
|
303
|
+
|
|
304
|
+
### Pipe Python output into shell commands
|
|
305
|
+
|
|
306
|
+
Bash:
|
|
307
|
+
```bash
|
|
308
|
+
python -c "print('\n'.join(str(i) for i in range(100)))" | grep 42
|
|
309
|
+
```
|
|
310
|
+
|
|
311
|
+
XmyShell:
|
|
312
|
+
```bash
|
|
313
|
+
print "\n".join(str(i) for i in range(100)) |> grep 42
|
|
314
|
+
```
|
|
315
|
+
|
|
316
|
+
Save the piped result into a variable:
|
|
317
|
+
|
|
318
|
+
Bash:
|
|
319
|
+
```bash
|
|
320
|
+
result=$(python -c "print('\n'.join(str(i) for i in range(100)))" | grep 42)
|
|
321
|
+
echo "$result"
|
|
322
|
+
```
|
|
323
|
+
|
|
324
|
+
XmyShell:
|
|
325
|
+
```bash
|
|
326
|
+
print "\n".join(str(i) for i in range(100)) |> grep 42 => result
|
|
327
|
+
print result
|
|
328
|
+
```
|
|
329
|
+
|
|
330
|
+
Note: in XmyShell, redirect `print` / `pyexec` output with `|>`, not `|`.
|
|
331
|
+
|
|
332
|
+
### Environment variables
|
|
333
|
+
|
|
334
|
+
Bash:
|
|
335
|
+
```bash
|
|
336
|
+
export ENV_VAR=foobar
|
|
337
|
+
echo "$ENV_VAR"
|
|
338
|
+
```
|
|
339
|
+
|
|
340
|
+
XmyShell:
|
|
341
|
+
```bash
|
|
342
|
+
pyexec foo = "foo"
|
|
343
|
+
export ENV_VAR={foo}bar
|
|
344
|
+
print ENV_VAR
|
|
345
|
+
```
|
|
346
|
+
|
|
347
|
+
Build an environment variable dynamically:
|
|
348
|
+
|
|
349
|
+
Bash:
|
|
350
|
+
```bash
|
|
351
|
+
export PROJECT_HOME="$HOME/projects/$(basename "$PWD")"
|
|
352
|
+
```
|
|
353
|
+
|
|
354
|
+
XmyShell:
|
|
355
|
+
```bash
|
|
356
|
+
export PROJECT_HOME={HOME_DIR + "/projects/" + basename(getcwd())}
|
|
357
|
+
```
|
|
358
|
+
|
|
359
|
+
### Aliases
|
|
360
|
+
|
|
361
|
+
Bash:
|
|
362
|
+
```bash
|
|
363
|
+
alias ll='ls -lh'
|
|
364
|
+
unalias ll
|
|
365
|
+
```
|
|
366
|
+
|
|
367
|
+
XmyShell:
|
|
368
|
+
```bash
|
|
369
|
+
alias ll='ls -lh'
|
|
370
|
+
unalias ll
|
|
371
|
+
```
|
|
372
|
+
|
|
373
|
+
The syntax is essentially the same.
|
|
374
|
+
|
|
375
|
+
### Run Python scripts / virtual environments
|
|
376
|
+
|
|
377
|
+
Run a Python script in Bash:
|
|
378
|
+
```bash
|
|
379
|
+
python script.py
|
|
380
|
+
```
|
|
381
|
+
|
|
382
|
+
In XmyShell, load a Python script into the persistent namespace of the current session:
|
|
383
|
+
```bash
|
|
384
|
+
source script.py
|
|
385
|
+
```
|
|
386
|
+
|
|
387
|
+
Activate a virtual environment:
|
|
388
|
+
|
|
389
|
+
Bash:
|
|
390
|
+
```bash
|
|
391
|
+
source .venv/bin/activate
|
|
392
|
+
```
|
|
393
|
+
|
|
394
|
+
XmyShell:
|
|
395
|
+
```bash
|
|
396
|
+
source .venv/bin/activate_this.py
|
|
397
|
+
```
|
|
398
|
+
|
|
399
|
+
Deactivate
|
|
400
|
+
|
|
401
|
+
Bash:
|
|
402
|
+
```bash
|
|
403
|
+
deactivate
|
|
404
|
+
```
|
|
405
|
+
|
|
406
|
+
XmyShell:
|
|
407
|
+
```bash
|
|
408
|
+
reload
|
|
409
|
+
```
|
|
410
|
+
|
|
411
|
+
XmyShell's `source` executes Python files via `runpy.run_path()`; it does not execute shell scripts. It also has no `deactivate`. Use `reload` to reset the environment.
|
|
412
|
+
|
|
413
|
+
### Check the exit code of the last command
|
|
414
|
+
|
|
415
|
+
Bash:
|
|
416
|
+
```bash
|
|
417
|
+
ls /nonexistent
|
|
418
|
+
echo $?
|
|
419
|
+
```
|
|
420
|
+
|
|
421
|
+
XmyShell:
|
|
422
|
+
```bash
|
|
423
|
+
ls /nonexistent
|
|
424
|
+
print exit_code
|
|
425
|
+
```
|
|
426
|
+
|
|
427
|
+
`exit_code` is a reserved XmyShell global variable that holds the exit code of the last command.
|
|
428
|
+
|
|
429
|
+
### Iterate over files and process them
|
|
430
|
+
|
|
431
|
+
Bash:
|
|
432
|
+
```bash
|
|
433
|
+
for f in *.txt; do
|
|
434
|
+
cp "$f" "$f.bak"
|
|
435
|
+
done
|
|
436
|
+
```
|
|
437
|
+
|
|
438
|
+
In XmyShell, this kind of task is usually better written directly in Python:
|
|
439
|
+
```bash
|
|
440
|
+
pyexec import shutil; [shutil.copy(f, f + ".bak") for f in os.listdir(".") if f.endswith(".txt")]
|
|
441
|
+
```
|
|
442
|
+
|
|
443
|
+
### Define a function with multiple lines
|
|
444
|
+
|
|
445
|
+
Bash:
|
|
446
|
+
```bash
|
|
447
|
+
greet() {
|
|
448
|
+
echo "Hello, $1!"
|
|
449
|
+
}
|
|
450
|
+
greet World
|
|
451
|
+
```
|
|
452
|
+
|
|
453
|
+
XmyShell:
|
|
454
|
+
```bash
|
|
455
|
+
pyexec
|
|
456
|
+
def greet(name):
|
|
457
|
+
return "Hello, " + name + "!"
|
|
458
|
+
pyexec greet("World")
|
|
459
|
+
```
|
|
460
|
+
|
|
461
|
+
The function definition stays in the persistent Python namespace of the current session.
|
|
462
|
+
|
|
463
|
+
---
|
|
464
|
+
|
|
465
|
+
### Notes
|
|
466
|
+
|
|
467
|
+
- `{...}` contains a Python expression, not Bash command substitution.
|
|
468
|
+
- `=>` saves command output into a Python variable.
|
|
469
|
+
- `|>` sends Python output from `print` / `pyexec` into a shell pipeline.
|
|
470
|
+
- External shell commands run in subprocesses and cannot modify the current directory or environment of the main XmyShell process. Use XmyShell's built-in `cd`, `export`, `alias`, etc. instead.
|
|
471
|
+
- `source` only executes Python scripts, not shell scripts.
|
|
472
|
+
|
|
214
473
|
|
|
215
474
|
## Limitations
|
|
216
475
|
|
|
@@ -222,8 +481,6 @@ from xmyshell.stubs import ... # stubs for built-in names
|
|
|
222
481
|
|
|
223
482
|
- **Shell scripts cannot modify the current environment** — Every external command runs in a fresh subprocess; `cd`, `export`, aliases, and function definitions inside a script are lost on exit.
|
|
224
483
|
|
|
225
|
-
- **No pipelines between built‑in commands** — `print` and `pyexec` do not support `|`. Use Python variables to pass data.
|
|
226
|
-
|
|
227
484
|
- **External command overhead** — Each subprocess spawns with minor delays.
|
|
228
485
|
|
|
229
486
|
**Why?** `XmyShell` is **NOT** a Bash replacement. It's a Python‑native environment for those who want Python's power at the command line.
|
|
@@ -29,27 +29,27 @@ Username@hostname ➜ ~ 0ms
|
|
|
29
29
|
|
|
30
30
|
- Persistent Python namespace across commands (variables, imports, functions)
|
|
31
31
|
- Expand inline Python expressions within `{}`, using independent namespace.
|
|
32
|
-
```
|
|
32
|
+
```bash
|
|
33
33
|
❯ mkdir {" ".join(f"test{i}" for i in range(10))}
|
|
34
34
|
❯ ls
|
|
35
35
|
test0 test1 test2 test3 test4 test5 test6 test7 test8 test9
|
|
36
36
|
```
|
|
37
37
|
|
|
38
38
|
- Evaluate and print Python expressions with `print`
|
|
39
|
-
```
|
|
39
|
+
```bash
|
|
40
40
|
❯ print 1 + 1
|
|
41
41
|
2
|
|
42
42
|
```
|
|
43
43
|
|
|
44
44
|
- Execute Python statements with `pyexec`
|
|
45
|
-
```
|
|
45
|
+
```bash
|
|
46
46
|
❯ pyexec files = [f for f in os.listdir('.') if f.endswith('.py')]
|
|
47
47
|
❯ print len(files)
|
|
48
48
|
3
|
|
49
49
|
```
|
|
50
50
|
|
|
51
51
|
- Capture command output into a Python variable with `=>`.
|
|
52
|
-
```
|
|
52
|
+
```bash
|
|
53
53
|
❯ which python => path
|
|
54
54
|
❯ print path
|
|
55
55
|
/usr/bin/python
|
|
@@ -59,14 +59,14 @@ test0 test1 test2 test3 test4 test5 test6 test7 test8 test9
|
|
|
59
59
|
```
|
|
60
60
|
|
|
61
61
|
- Redirect the output of Python commands (`print`, `pyexec`) with `|>`
|
|
62
|
-
```
|
|
62
|
+
```bash
|
|
63
63
|
❯ print "\n".join(str(i) for i in range(100)) |> grep 42 => result
|
|
64
64
|
❯ print result
|
|
65
65
|
42
|
|
66
66
|
```
|
|
67
67
|
|
|
68
68
|
- Built-in `source` command to run python scripts.
|
|
69
|
-
```
|
|
69
|
+
```bash
|
|
70
70
|
❯ which python
|
|
71
71
|
/usr/bin/python
|
|
72
72
|
❯ source .venv/bin/activate_this.py
|
|
@@ -75,7 +75,7 @@ test0 test1 test2 test3 test4 test5 test6 test7 test8 test9
|
|
|
75
75
|
```
|
|
76
76
|
|
|
77
77
|
- Built-in `export` command.
|
|
78
|
-
```
|
|
78
|
+
```bash
|
|
79
79
|
❯ pyexec foo = "foo"
|
|
80
80
|
❯ export ENV_VAR={foo}bar
|
|
81
81
|
❯ print ENV_VAR
|
|
@@ -83,27 +83,27 @@ foobar
|
|
|
83
83
|
```
|
|
84
84
|
|
|
85
85
|
- Built-in `import` command.
|
|
86
|
-
```
|
|
86
|
+
```bash
|
|
87
87
|
❯ import numpy as np
|
|
88
88
|
❯ from math import *
|
|
89
89
|
```
|
|
90
90
|
|
|
91
91
|
- Reload with `reload` command.
|
|
92
|
-
```
|
|
92
|
+
```bash
|
|
93
93
|
❯ reload
|
|
94
94
|
```
|
|
95
95
|
|
|
96
96
|
- Update xmyshell (optionally to a specific version).
|
|
97
|
-
```
|
|
97
|
+
```bash
|
|
98
98
|
❯ udpate
|
|
99
99
|
```
|
|
100
100
|
or
|
|
101
|
-
```
|
|
101
|
+
```bash
|
|
102
102
|
❯ update 0.1.3
|
|
103
103
|
```
|
|
104
104
|
|
|
105
105
|
- Alias
|
|
106
|
-
```
|
|
106
|
+
```bash
|
|
107
107
|
❯ alias ll='ls -lh'
|
|
108
108
|
❯ unalias ll
|
|
109
109
|
```
|
|
@@ -112,17 +112,16 @@ or
|
|
|
112
112
|
E.g. `{["arg1", "arg2 xxx"]}` will be expanded into `arg1 'arg2 xxx'`
|
|
113
113
|
|
|
114
114
|
Here is an example (though there are other ways to do this, it is just an example )
|
|
115
|
-
```
|
|
115
|
+
```bash
|
|
116
116
|
❯ pip install {cat("requirements.txt").splitlines()}
|
|
117
117
|
```
|
|
118
118
|
|
|
119
119
|
- Multiline input with ending `\`.
|
|
120
|
-
```
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
[~] $ pyexec foo()
|
|
120
|
+
```python
|
|
121
|
+
❯ pyexec
|
|
122
|
+
def foo():
|
|
123
|
+
print("Hello!")
|
|
124
|
+
❯ pyexec foo()
|
|
126
125
|
Hello!
|
|
127
126
|
```
|
|
128
127
|
|
|
@@ -201,6 +200,266 @@ from xmyshell.themes import ... # themes
|
|
|
201
200
|
from xmyshell.stubs import ... # stubs for built-in names
|
|
202
201
|
```
|
|
203
202
|
|
|
203
|
+
## Examples / Bash Equivalents
|
|
204
|
+
|
|
205
|
+
Here are some equivalent forms of common Bash patterns.
|
|
206
|
+
|
|
207
|
+
### Capture command output into a variable
|
|
208
|
+
|
|
209
|
+
Bash:
|
|
210
|
+
```bash
|
|
211
|
+
python_path=$(which python)
|
|
212
|
+
echo "Python is at $python_path"
|
|
213
|
+
```
|
|
214
|
+
|
|
215
|
+
XmyShell:
|
|
216
|
+
```bash
|
|
217
|
+
which python => python_path
|
|
218
|
+
print "Python is at " + python_path
|
|
219
|
+
```
|
|
220
|
+
|
|
221
|
+
### Expand file contents into command arguments
|
|
222
|
+
|
|
223
|
+
Bash:
|
|
224
|
+
```bash
|
|
225
|
+
pip install $(cat requirements.txt)
|
|
226
|
+
```
|
|
227
|
+
|
|
228
|
+
XmyShell:
|
|
229
|
+
```bash
|
|
230
|
+
pip install {cat("requirements.txt").splitlines()}
|
|
231
|
+
```
|
|
232
|
+
|
|
233
|
+
`cat()` is a built-in XmyShell helper equivalent to `open(file).read()`. The list returned by `splitlines()` is expanded into separate shell arguments.
|
|
234
|
+
|
|
235
|
+
### Brace expansion / sequence expansion
|
|
236
|
+
|
|
237
|
+
Bash:
|
|
238
|
+
```bash
|
|
239
|
+
echo {0..4}
|
|
240
|
+
```
|
|
241
|
+
|
|
242
|
+
XmyShell:
|
|
243
|
+
```bash
|
|
244
|
+
echo {range(5)}
|
|
245
|
+
```
|
|
246
|
+
|
|
247
|
+
Bash:
|
|
248
|
+
```bash
|
|
249
|
+
touch file{0..4}
|
|
250
|
+
```
|
|
251
|
+
|
|
252
|
+
XmyShell:
|
|
253
|
+
```bash
|
|
254
|
+
touch {f"file{i}" for i in range(5)}
|
|
255
|
+
```
|
|
256
|
+
|
|
257
|
+
Bash:
|
|
258
|
+
```bash
|
|
259
|
+
mkdir test{0..9}
|
|
260
|
+
```
|
|
261
|
+
|
|
262
|
+
XmyShell:
|
|
263
|
+
```bash
|
|
264
|
+
mkdir {f"test{i}" for i in range(10)}
|
|
265
|
+
```
|
|
266
|
+
|
|
267
|
+
Lists, tuples, generators, and similar iterables are expanded into separate shell arguments.
|
|
268
|
+
|
|
269
|
+
### Python expressions and statements
|
|
270
|
+
|
|
271
|
+
Bash:
|
|
272
|
+
```bash
|
|
273
|
+
python -c 'print(1 + 1)'
|
|
274
|
+
```
|
|
275
|
+
|
|
276
|
+
XmyShell:
|
|
277
|
+
```bash
|
|
278
|
+
print 1 + 1
|
|
279
|
+
```
|
|
280
|
+
|
|
281
|
+
Bash:
|
|
282
|
+
```bash
|
|
283
|
+
python -c 'files=[f for f in __import__("os").listdir(".") if f.endswith(".py")]; print(len(files))'
|
|
284
|
+
```
|
|
285
|
+
|
|
286
|
+
XmyShell:
|
|
287
|
+
```bash
|
|
288
|
+
pyexec files = [f for f in os.listdir(".") if f.endswith(".py")]
|
|
289
|
+
print len(files)
|
|
290
|
+
```
|
|
291
|
+
|
|
292
|
+
`pyexec` executes Python statements and keeps them in the persistent Python namespace.
|
|
293
|
+
|
|
294
|
+
### Pipe Python output into shell commands
|
|
295
|
+
|
|
296
|
+
Bash:
|
|
297
|
+
```bash
|
|
298
|
+
python -c "print('\n'.join(str(i) for i in range(100)))" | grep 42
|
|
299
|
+
```
|
|
300
|
+
|
|
301
|
+
XmyShell:
|
|
302
|
+
```bash
|
|
303
|
+
print "\n".join(str(i) for i in range(100)) |> grep 42
|
|
304
|
+
```
|
|
305
|
+
|
|
306
|
+
Save the piped result into a variable:
|
|
307
|
+
|
|
308
|
+
Bash:
|
|
309
|
+
```bash
|
|
310
|
+
result=$(python -c "print('\n'.join(str(i) for i in range(100)))" | grep 42)
|
|
311
|
+
echo "$result"
|
|
312
|
+
```
|
|
313
|
+
|
|
314
|
+
XmyShell:
|
|
315
|
+
```bash
|
|
316
|
+
print "\n".join(str(i) for i in range(100)) |> grep 42 => result
|
|
317
|
+
print result
|
|
318
|
+
```
|
|
319
|
+
|
|
320
|
+
Note: in XmyShell, redirect `print` / `pyexec` output with `|>`, not `|`.
|
|
321
|
+
|
|
322
|
+
### Environment variables
|
|
323
|
+
|
|
324
|
+
Bash:
|
|
325
|
+
```bash
|
|
326
|
+
export ENV_VAR=foobar
|
|
327
|
+
echo "$ENV_VAR"
|
|
328
|
+
```
|
|
329
|
+
|
|
330
|
+
XmyShell:
|
|
331
|
+
```bash
|
|
332
|
+
pyexec foo = "foo"
|
|
333
|
+
export ENV_VAR={foo}bar
|
|
334
|
+
print ENV_VAR
|
|
335
|
+
```
|
|
336
|
+
|
|
337
|
+
Build an environment variable dynamically:
|
|
338
|
+
|
|
339
|
+
Bash:
|
|
340
|
+
```bash
|
|
341
|
+
export PROJECT_HOME="$HOME/projects/$(basename "$PWD")"
|
|
342
|
+
```
|
|
343
|
+
|
|
344
|
+
XmyShell:
|
|
345
|
+
```bash
|
|
346
|
+
export PROJECT_HOME={HOME_DIR + "/projects/" + basename(getcwd())}
|
|
347
|
+
```
|
|
348
|
+
|
|
349
|
+
### Aliases
|
|
350
|
+
|
|
351
|
+
Bash:
|
|
352
|
+
```bash
|
|
353
|
+
alias ll='ls -lh'
|
|
354
|
+
unalias ll
|
|
355
|
+
```
|
|
356
|
+
|
|
357
|
+
XmyShell:
|
|
358
|
+
```bash
|
|
359
|
+
alias ll='ls -lh'
|
|
360
|
+
unalias ll
|
|
361
|
+
```
|
|
362
|
+
|
|
363
|
+
The syntax is essentially the same.
|
|
364
|
+
|
|
365
|
+
### Run Python scripts / virtual environments
|
|
366
|
+
|
|
367
|
+
Run a Python script in Bash:
|
|
368
|
+
```bash
|
|
369
|
+
python script.py
|
|
370
|
+
```
|
|
371
|
+
|
|
372
|
+
In XmyShell, load a Python script into the persistent namespace of the current session:
|
|
373
|
+
```bash
|
|
374
|
+
source script.py
|
|
375
|
+
```
|
|
376
|
+
|
|
377
|
+
Activate a virtual environment:
|
|
378
|
+
|
|
379
|
+
Bash:
|
|
380
|
+
```bash
|
|
381
|
+
source .venv/bin/activate
|
|
382
|
+
```
|
|
383
|
+
|
|
384
|
+
XmyShell:
|
|
385
|
+
```bash
|
|
386
|
+
source .venv/bin/activate_this.py
|
|
387
|
+
```
|
|
388
|
+
|
|
389
|
+
Deactivate
|
|
390
|
+
|
|
391
|
+
Bash:
|
|
392
|
+
```bash
|
|
393
|
+
deactivate
|
|
394
|
+
```
|
|
395
|
+
|
|
396
|
+
XmyShell:
|
|
397
|
+
```bash
|
|
398
|
+
reload
|
|
399
|
+
```
|
|
400
|
+
|
|
401
|
+
XmyShell's `source` executes Python files via `runpy.run_path()`; it does not execute shell scripts. It also has no `deactivate`. Use `reload` to reset the environment.
|
|
402
|
+
|
|
403
|
+
### Check the exit code of the last command
|
|
404
|
+
|
|
405
|
+
Bash:
|
|
406
|
+
```bash
|
|
407
|
+
ls /nonexistent
|
|
408
|
+
echo $?
|
|
409
|
+
```
|
|
410
|
+
|
|
411
|
+
XmyShell:
|
|
412
|
+
```bash
|
|
413
|
+
ls /nonexistent
|
|
414
|
+
print exit_code
|
|
415
|
+
```
|
|
416
|
+
|
|
417
|
+
`exit_code` is a reserved XmyShell global variable that holds the exit code of the last command.
|
|
418
|
+
|
|
419
|
+
### Iterate over files and process them
|
|
420
|
+
|
|
421
|
+
Bash:
|
|
422
|
+
```bash
|
|
423
|
+
for f in *.txt; do
|
|
424
|
+
cp "$f" "$f.bak"
|
|
425
|
+
done
|
|
426
|
+
```
|
|
427
|
+
|
|
428
|
+
In XmyShell, this kind of task is usually better written directly in Python:
|
|
429
|
+
```bash
|
|
430
|
+
pyexec import shutil; [shutil.copy(f, f + ".bak") for f in os.listdir(".") if f.endswith(".txt")]
|
|
431
|
+
```
|
|
432
|
+
|
|
433
|
+
### Define a function with multiple lines
|
|
434
|
+
|
|
435
|
+
Bash:
|
|
436
|
+
```bash
|
|
437
|
+
greet() {
|
|
438
|
+
echo "Hello, $1!"
|
|
439
|
+
}
|
|
440
|
+
greet World
|
|
441
|
+
```
|
|
442
|
+
|
|
443
|
+
XmyShell:
|
|
444
|
+
```bash
|
|
445
|
+
pyexec
|
|
446
|
+
def greet(name):
|
|
447
|
+
return "Hello, " + name + "!"
|
|
448
|
+
pyexec greet("World")
|
|
449
|
+
```
|
|
450
|
+
|
|
451
|
+
The function definition stays in the persistent Python namespace of the current session.
|
|
452
|
+
|
|
453
|
+
---
|
|
454
|
+
|
|
455
|
+
### Notes
|
|
456
|
+
|
|
457
|
+
- `{...}` contains a Python expression, not Bash command substitution.
|
|
458
|
+
- `=>` saves command output into a Python variable.
|
|
459
|
+
- `|>` sends Python output from `print` / `pyexec` into a shell pipeline.
|
|
460
|
+
- External shell commands run in subprocesses and cannot modify the current directory or environment of the main XmyShell process. Use XmyShell's built-in `cd`, `export`, `alias`, etc. instead.
|
|
461
|
+
- `source` only executes Python scripts, not shell scripts.
|
|
462
|
+
|
|
204
463
|
|
|
205
464
|
## Limitations
|
|
206
465
|
|
|
@@ -212,8 +471,6 @@ from xmyshell.stubs import ... # stubs for built-in names
|
|
|
212
471
|
|
|
213
472
|
- **Shell scripts cannot modify the current environment** — Every external command runs in a fresh subprocess; `cd`, `export`, aliases, and function definitions inside a script are lost on exit.
|
|
214
473
|
|
|
215
|
-
- **No pipelines between built‑in commands** — `print` and `pyexec` do not support `|`. Use Python variables to pass data.
|
|
216
|
-
|
|
217
474
|
- **External command overhead** — Each subprocess spawns with minor delays.
|
|
218
475
|
|
|
219
476
|
**Why?** `XmyShell` is **NOT** a Bash replacement. It's a Python‑native environment for those who want Python's power at the command line.
|
|
@@ -7,6 +7,7 @@ import runpy
|
|
|
7
7
|
import subprocess
|
|
8
8
|
import signal
|
|
9
9
|
import shlex
|
|
10
|
+
from webbrowser import get
|
|
10
11
|
from .environment import localspace, aliases, xmyshell_alias, xmyshell_unalias, SHELL_CMD
|
|
11
12
|
from .utils import pywarning, pyerror, getcwd
|
|
12
13
|
from .meta import HELP_MESSAGE
|
|
@@ -89,7 +90,7 @@ def pyeval(cmd_line: str) -> str:
|
|
|
89
90
|
expr = cmd_line[i+1:j-1].strip()
|
|
90
91
|
if expr:
|
|
91
92
|
try:
|
|
92
|
-
val = eval(expr, localspace, localspace)
|
|
93
|
+
val = eval(f"({expr})", localspace, localspace)
|
|
93
94
|
if not isinstance(
|
|
94
95
|
val, (str, bytes, bytearray, memoryview)
|
|
95
96
|
) and isinstance(val, (Sequence, Generator)):
|
|
@@ -266,7 +267,7 @@ def xmyshell(cmd_line: str) -> int:
|
|
|
266
267
|
sys.stdout = old_stdout
|
|
267
268
|
if target_var:
|
|
268
269
|
result, _ = proc.communicate()
|
|
269
|
-
localspace[target_var] = result
|
|
270
|
+
localspace[target_var] = result.rstrip('\n')
|
|
270
271
|
return proc.returncode
|
|
271
272
|
else:
|
|
272
273
|
return proc.wait()
|
|
@@ -278,7 +279,7 @@ def xmyshell(cmd_line: str) -> int:
|
|
|
278
279
|
with redirect_stdout(f):
|
|
279
280
|
return_code = xmyshell_raw_command(cmd_line)
|
|
280
281
|
if return_code is not None:
|
|
281
|
-
localspace[target_var] = f.getvalue()
|
|
282
|
+
localspace[target_var] = f.getvalue().rstrip('\n')
|
|
282
283
|
return return_code
|
|
283
284
|
else:
|
|
284
285
|
return_code = xmyshell_raw_command(cmd_line)
|
|
@@ -304,6 +305,9 @@ def xmyshell(cmd_line: str) -> int:
|
|
|
304
305
|
case "cd":
|
|
305
306
|
splited = cmd_line.split(maxsplit=1)
|
|
306
307
|
target_dir = "~" if len(splited) <= 1 else splited[1].strip()
|
|
308
|
+
if target_dir == '-':
|
|
309
|
+
target_dir = os.environ.get("OLDPWD", getcwd())
|
|
310
|
+
print(target_dir)
|
|
307
311
|
try:
|
|
308
312
|
target_dir = os.path.expanduser(target_dir)
|
|
309
313
|
# only works on Windows
|
|
@@ -319,6 +323,7 @@ def xmyshell(cmd_line: str) -> int:
|
|
|
319
323
|
if len(_splited) > 1:
|
|
320
324
|
pyerror("too many arguments")
|
|
321
325
|
return -1
|
|
326
|
+
os.environ["OLDPWD"] = getcwd()
|
|
322
327
|
os.chdir(_splited[0])
|
|
323
328
|
return 0
|
|
324
329
|
except FileNotFoundError:
|
|
@@ -349,7 +354,7 @@ def xmyshell(cmd_line: str) -> int:
|
|
|
349
354
|
result = _run(
|
|
350
355
|
cmd_line, env=os.environ, capture_output=True, text=True
|
|
351
356
|
)
|
|
352
|
-
localspace[target_var] = result.stdout
|
|
357
|
+
localspace[target_var] = str(result.stdout).rstrip('\n')
|
|
353
358
|
else:
|
|
354
359
|
result = _run(cmd_line, env=os.environ)
|
|
355
360
|
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import time
|
|
2
2
|
from prompt_toolkit.buffer import Buffer
|
|
3
|
-
from prompt_toolkit.filters import has_completions
|
|
3
|
+
from prompt_toolkit.filters import has_completions, is_searching
|
|
4
4
|
from prompt_toolkit.key_binding import KeyBindings, KeyPressEvent
|
|
5
5
|
from prompt_toolkit.selection import SelectionState
|
|
6
6
|
from prompt_toolkit.keys import Keys
|
|
@@ -374,7 +374,7 @@ def _(event: KeyPressEvent) -> None:
|
|
|
374
374
|
else:
|
|
375
375
|
buffer.insert_text(" ")
|
|
376
376
|
|
|
377
|
-
@bindings.add(Keys.Enter)
|
|
377
|
+
@bindings.add(Keys.Enter, filter=~is_searching)
|
|
378
378
|
def _(event: KeyPressEvent):
|
|
379
379
|
buffer = event.current_buffer
|
|
380
380
|
current_line = buffer.document.current_line_before_cursor
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.4
|
|
2
2
|
Name: xmyshell
|
|
3
|
-
Version: 0.2.
|
|
3
|
+
Version: 0.2.23
|
|
4
4
|
Summary: XmyShell is a shell-like tool built on top of prompt_toolkit which provides a persistent Python runtime.
|
|
5
5
|
Requires-Python: >=3.12
|
|
6
6
|
Description-Content-Type: text/markdown
|
|
@@ -39,27 +39,27 @@ Username@hostname ➜ ~ 0ms
|
|
|
39
39
|
|
|
40
40
|
- Persistent Python namespace across commands (variables, imports, functions)
|
|
41
41
|
- Expand inline Python expressions within `{}`, using independent namespace.
|
|
42
|
-
```
|
|
42
|
+
```bash
|
|
43
43
|
❯ mkdir {" ".join(f"test{i}" for i in range(10))}
|
|
44
44
|
❯ ls
|
|
45
45
|
test0 test1 test2 test3 test4 test5 test6 test7 test8 test9
|
|
46
46
|
```
|
|
47
47
|
|
|
48
48
|
- Evaluate and print Python expressions with `print`
|
|
49
|
-
```
|
|
49
|
+
```bash
|
|
50
50
|
❯ print 1 + 1
|
|
51
51
|
2
|
|
52
52
|
```
|
|
53
53
|
|
|
54
54
|
- Execute Python statements with `pyexec`
|
|
55
|
-
```
|
|
55
|
+
```bash
|
|
56
56
|
❯ pyexec files = [f for f in os.listdir('.') if f.endswith('.py')]
|
|
57
57
|
❯ print len(files)
|
|
58
58
|
3
|
|
59
59
|
```
|
|
60
60
|
|
|
61
61
|
- Capture command output into a Python variable with `=>`.
|
|
62
|
-
```
|
|
62
|
+
```bash
|
|
63
63
|
❯ which python => path
|
|
64
64
|
❯ print path
|
|
65
65
|
/usr/bin/python
|
|
@@ -69,14 +69,14 @@ test0 test1 test2 test3 test4 test5 test6 test7 test8 test9
|
|
|
69
69
|
```
|
|
70
70
|
|
|
71
71
|
- Redirect the output of Python commands (`print`, `pyexec`) with `|>`
|
|
72
|
-
```
|
|
72
|
+
```bash
|
|
73
73
|
❯ print "\n".join(str(i) for i in range(100)) |> grep 42 => result
|
|
74
74
|
❯ print result
|
|
75
75
|
42
|
|
76
76
|
```
|
|
77
77
|
|
|
78
78
|
- Built-in `source` command to run python scripts.
|
|
79
|
-
```
|
|
79
|
+
```bash
|
|
80
80
|
❯ which python
|
|
81
81
|
/usr/bin/python
|
|
82
82
|
❯ source .venv/bin/activate_this.py
|
|
@@ -85,7 +85,7 @@ test0 test1 test2 test3 test4 test5 test6 test7 test8 test9
|
|
|
85
85
|
```
|
|
86
86
|
|
|
87
87
|
- Built-in `export` command.
|
|
88
|
-
```
|
|
88
|
+
```bash
|
|
89
89
|
❯ pyexec foo = "foo"
|
|
90
90
|
❯ export ENV_VAR={foo}bar
|
|
91
91
|
❯ print ENV_VAR
|
|
@@ -93,27 +93,27 @@ foobar
|
|
|
93
93
|
```
|
|
94
94
|
|
|
95
95
|
- Built-in `import` command.
|
|
96
|
-
```
|
|
96
|
+
```bash
|
|
97
97
|
❯ import numpy as np
|
|
98
98
|
❯ from math import *
|
|
99
99
|
```
|
|
100
100
|
|
|
101
101
|
- Reload with `reload` command.
|
|
102
|
-
```
|
|
102
|
+
```bash
|
|
103
103
|
❯ reload
|
|
104
104
|
```
|
|
105
105
|
|
|
106
106
|
- Update xmyshell (optionally to a specific version).
|
|
107
|
-
```
|
|
107
|
+
```bash
|
|
108
108
|
❯ udpate
|
|
109
109
|
```
|
|
110
110
|
or
|
|
111
|
-
```
|
|
111
|
+
```bash
|
|
112
112
|
❯ update 0.1.3
|
|
113
113
|
```
|
|
114
114
|
|
|
115
115
|
- Alias
|
|
116
|
-
```
|
|
116
|
+
```bash
|
|
117
117
|
❯ alias ll='ls -lh'
|
|
118
118
|
❯ unalias ll
|
|
119
119
|
```
|
|
@@ -122,17 +122,16 @@ or
|
|
|
122
122
|
E.g. `{["arg1", "arg2 xxx"]}` will be expanded into `arg1 'arg2 xxx'`
|
|
123
123
|
|
|
124
124
|
Here is an example (though there are other ways to do this, it is just an example )
|
|
125
|
-
```
|
|
125
|
+
```bash
|
|
126
126
|
❯ pip install {cat("requirements.txt").splitlines()}
|
|
127
127
|
```
|
|
128
128
|
|
|
129
129
|
- Multiline input with ending `\`.
|
|
130
|
-
```
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
[~] $ pyexec foo()
|
|
130
|
+
```python
|
|
131
|
+
❯ pyexec
|
|
132
|
+
def foo():
|
|
133
|
+
print("Hello!")
|
|
134
|
+
❯ pyexec foo()
|
|
136
135
|
Hello!
|
|
137
136
|
```
|
|
138
137
|
|
|
@@ -211,6 +210,266 @@ from xmyshell.themes import ... # themes
|
|
|
211
210
|
from xmyshell.stubs import ... # stubs for built-in names
|
|
212
211
|
```
|
|
213
212
|
|
|
213
|
+
## Examples / Bash Equivalents
|
|
214
|
+
|
|
215
|
+
Here are some equivalent forms of common Bash patterns.
|
|
216
|
+
|
|
217
|
+
### Capture command output into a variable
|
|
218
|
+
|
|
219
|
+
Bash:
|
|
220
|
+
```bash
|
|
221
|
+
python_path=$(which python)
|
|
222
|
+
echo "Python is at $python_path"
|
|
223
|
+
```
|
|
224
|
+
|
|
225
|
+
XmyShell:
|
|
226
|
+
```bash
|
|
227
|
+
which python => python_path
|
|
228
|
+
print "Python is at " + python_path
|
|
229
|
+
```
|
|
230
|
+
|
|
231
|
+
### Expand file contents into command arguments
|
|
232
|
+
|
|
233
|
+
Bash:
|
|
234
|
+
```bash
|
|
235
|
+
pip install $(cat requirements.txt)
|
|
236
|
+
```
|
|
237
|
+
|
|
238
|
+
XmyShell:
|
|
239
|
+
```bash
|
|
240
|
+
pip install {cat("requirements.txt").splitlines()}
|
|
241
|
+
```
|
|
242
|
+
|
|
243
|
+
`cat()` is a built-in XmyShell helper equivalent to `open(file).read()`. The list returned by `splitlines()` is expanded into separate shell arguments.
|
|
244
|
+
|
|
245
|
+
### Brace expansion / sequence expansion
|
|
246
|
+
|
|
247
|
+
Bash:
|
|
248
|
+
```bash
|
|
249
|
+
echo {0..4}
|
|
250
|
+
```
|
|
251
|
+
|
|
252
|
+
XmyShell:
|
|
253
|
+
```bash
|
|
254
|
+
echo {range(5)}
|
|
255
|
+
```
|
|
256
|
+
|
|
257
|
+
Bash:
|
|
258
|
+
```bash
|
|
259
|
+
touch file{0..4}
|
|
260
|
+
```
|
|
261
|
+
|
|
262
|
+
XmyShell:
|
|
263
|
+
```bash
|
|
264
|
+
touch {f"file{i}" for i in range(5)}
|
|
265
|
+
```
|
|
266
|
+
|
|
267
|
+
Bash:
|
|
268
|
+
```bash
|
|
269
|
+
mkdir test{0..9}
|
|
270
|
+
```
|
|
271
|
+
|
|
272
|
+
XmyShell:
|
|
273
|
+
```bash
|
|
274
|
+
mkdir {f"test{i}" for i in range(10)}
|
|
275
|
+
```
|
|
276
|
+
|
|
277
|
+
Lists, tuples, generators, and similar iterables are expanded into separate shell arguments.
|
|
278
|
+
|
|
279
|
+
### Python expressions and statements
|
|
280
|
+
|
|
281
|
+
Bash:
|
|
282
|
+
```bash
|
|
283
|
+
python -c 'print(1 + 1)'
|
|
284
|
+
```
|
|
285
|
+
|
|
286
|
+
XmyShell:
|
|
287
|
+
```bash
|
|
288
|
+
print 1 + 1
|
|
289
|
+
```
|
|
290
|
+
|
|
291
|
+
Bash:
|
|
292
|
+
```bash
|
|
293
|
+
python -c 'files=[f for f in __import__("os").listdir(".") if f.endswith(".py")]; print(len(files))'
|
|
294
|
+
```
|
|
295
|
+
|
|
296
|
+
XmyShell:
|
|
297
|
+
```bash
|
|
298
|
+
pyexec files = [f for f in os.listdir(".") if f.endswith(".py")]
|
|
299
|
+
print len(files)
|
|
300
|
+
```
|
|
301
|
+
|
|
302
|
+
`pyexec` executes Python statements and keeps them in the persistent Python namespace.
|
|
303
|
+
|
|
304
|
+
### Pipe Python output into shell commands
|
|
305
|
+
|
|
306
|
+
Bash:
|
|
307
|
+
```bash
|
|
308
|
+
python -c "print('\n'.join(str(i) for i in range(100)))" | grep 42
|
|
309
|
+
```
|
|
310
|
+
|
|
311
|
+
XmyShell:
|
|
312
|
+
```bash
|
|
313
|
+
print "\n".join(str(i) for i in range(100)) |> grep 42
|
|
314
|
+
```
|
|
315
|
+
|
|
316
|
+
Save the piped result into a variable:
|
|
317
|
+
|
|
318
|
+
Bash:
|
|
319
|
+
```bash
|
|
320
|
+
result=$(python -c "print('\n'.join(str(i) for i in range(100)))" | grep 42)
|
|
321
|
+
echo "$result"
|
|
322
|
+
```
|
|
323
|
+
|
|
324
|
+
XmyShell:
|
|
325
|
+
```bash
|
|
326
|
+
print "\n".join(str(i) for i in range(100)) |> grep 42 => result
|
|
327
|
+
print result
|
|
328
|
+
```
|
|
329
|
+
|
|
330
|
+
Note: in XmyShell, redirect `print` / `pyexec` output with `|>`, not `|`.
|
|
331
|
+
|
|
332
|
+
### Environment variables
|
|
333
|
+
|
|
334
|
+
Bash:
|
|
335
|
+
```bash
|
|
336
|
+
export ENV_VAR=foobar
|
|
337
|
+
echo "$ENV_VAR"
|
|
338
|
+
```
|
|
339
|
+
|
|
340
|
+
XmyShell:
|
|
341
|
+
```bash
|
|
342
|
+
pyexec foo = "foo"
|
|
343
|
+
export ENV_VAR={foo}bar
|
|
344
|
+
print ENV_VAR
|
|
345
|
+
```
|
|
346
|
+
|
|
347
|
+
Build an environment variable dynamically:
|
|
348
|
+
|
|
349
|
+
Bash:
|
|
350
|
+
```bash
|
|
351
|
+
export PROJECT_HOME="$HOME/projects/$(basename "$PWD")"
|
|
352
|
+
```
|
|
353
|
+
|
|
354
|
+
XmyShell:
|
|
355
|
+
```bash
|
|
356
|
+
export PROJECT_HOME={HOME_DIR + "/projects/" + basename(getcwd())}
|
|
357
|
+
```
|
|
358
|
+
|
|
359
|
+
### Aliases
|
|
360
|
+
|
|
361
|
+
Bash:
|
|
362
|
+
```bash
|
|
363
|
+
alias ll='ls -lh'
|
|
364
|
+
unalias ll
|
|
365
|
+
```
|
|
366
|
+
|
|
367
|
+
XmyShell:
|
|
368
|
+
```bash
|
|
369
|
+
alias ll='ls -lh'
|
|
370
|
+
unalias ll
|
|
371
|
+
```
|
|
372
|
+
|
|
373
|
+
The syntax is essentially the same.
|
|
374
|
+
|
|
375
|
+
### Run Python scripts / virtual environments
|
|
376
|
+
|
|
377
|
+
Run a Python script in Bash:
|
|
378
|
+
```bash
|
|
379
|
+
python script.py
|
|
380
|
+
```
|
|
381
|
+
|
|
382
|
+
In XmyShell, load a Python script into the persistent namespace of the current session:
|
|
383
|
+
```bash
|
|
384
|
+
source script.py
|
|
385
|
+
```
|
|
386
|
+
|
|
387
|
+
Activate a virtual environment:
|
|
388
|
+
|
|
389
|
+
Bash:
|
|
390
|
+
```bash
|
|
391
|
+
source .venv/bin/activate
|
|
392
|
+
```
|
|
393
|
+
|
|
394
|
+
XmyShell:
|
|
395
|
+
```bash
|
|
396
|
+
source .venv/bin/activate_this.py
|
|
397
|
+
```
|
|
398
|
+
|
|
399
|
+
Deactivate
|
|
400
|
+
|
|
401
|
+
Bash:
|
|
402
|
+
```bash
|
|
403
|
+
deactivate
|
|
404
|
+
```
|
|
405
|
+
|
|
406
|
+
XmyShell:
|
|
407
|
+
```bash
|
|
408
|
+
reload
|
|
409
|
+
```
|
|
410
|
+
|
|
411
|
+
XmyShell's `source` executes Python files via `runpy.run_path()`; it does not execute shell scripts. It also has no `deactivate`. Use `reload` to reset the environment.
|
|
412
|
+
|
|
413
|
+
### Check the exit code of the last command
|
|
414
|
+
|
|
415
|
+
Bash:
|
|
416
|
+
```bash
|
|
417
|
+
ls /nonexistent
|
|
418
|
+
echo $?
|
|
419
|
+
```
|
|
420
|
+
|
|
421
|
+
XmyShell:
|
|
422
|
+
```bash
|
|
423
|
+
ls /nonexistent
|
|
424
|
+
print exit_code
|
|
425
|
+
```
|
|
426
|
+
|
|
427
|
+
`exit_code` is a reserved XmyShell global variable that holds the exit code of the last command.
|
|
428
|
+
|
|
429
|
+
### Iterate over files and process them
|
|
430
|
+
|
|
431
|
+
Bash:
|
|
432
|
+
```bash
|
|
433
|
+
for f in *.txt; do
|
|
434
|
+
cp "$f" "$f.bak"
|
|
435
|
+
done
|
|
436
|
+
```
|
|
437
|
+
|
|
438
|
+
In XmyShell, this kind of task is usually better written directly in Python:
|
|
439
|
+
```bash
|
|
440
|
+
pyexec import shutil; [shutil.copy(f, f + ".bak") for f in os.listdir(".") if f.endswith(".txt")]
|
|
441
|
+
```
|
|
442
|
+
|
|
443
|
+
### Define a function with multiple lines
|
|
444
|
+
|
|
445
|
+
Bash:
|
|
446
|
+
```bash
|
|
447
|
+
greet() {
|
|
448
|
+
echo "Hello, $1!"
|
|
449
|
+
}
|
|
450
|
+
greet World
|
|
451
|
+
```
|
|
452
|
+
|
|
453
|
+
XmyShell:
|
|
454
|
+
```bash
|
|
455
|
+
pyexec
|
|
456
|
+
def greet(name):
|
|
457
|
+
return "Hello, " + name + "!"
|
|
458
|
+
pyexec greet("World")
|
|
459
|
+
```
|
|
460
|
+
|
|
461
|
+
The function definition stays in the persistent Python namespace of the current session.
|
|
462
|
+
|
|
463
|
+
---
|
|
464
|
+
|
|
465
|
+
### Notes
|
|
466
|
+
|
|
467
|
+
- `{...}` contains a Python expression, not Bash command substitution.
|
|
468
|
+
- `=>` saves command output into a Python variable.
|
|
469
|
+
- `|>` sends Python output from `print` / `pyexec` into a shell pipeline.
|
|
470
|
+
- External shell commands run in subprocesses and cannot modify the current directory or environment of the main XmyShell process. Use XmyShell's built-in `cd`, `export`, `alias`, etc. instead.
|
|
471
|
+
- `source` only executes Python scripts, not shell scripts.
|
|
472
|
+
|
|
214
473
|
|
|
215
474
|
## Limitations
|
|
216
475
|
|
|
@@ -222,8 +481,6 @@ from xmyshell.stubs import ... # stubs for built-in names
|
|
|
222
481
|
|
|
223
482
|
- **Shell scripts cannot modify the current environment** — Every external command runs in a fresh subprocess; `cd`, `export`, aliases, and function definitions inside a script are lost on exit.
|
|
224
483
|
|
|
225
|
-
- **No pipelines between built‑in commands** — `print` and `pyexec` do not support `|`. Use Python variables to pass data.
|
|
226
|
-
|
|
227
484
|
- **External command overhead** — Each subprocess spawns with minor delays.
|
|
228
485
|
|
|
229
486
|
**Why?** `XmyShell` is **NOT** a Bash replacement. It's a Python‑native environment for those who want Python's power at the command line.
|
|
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
|