xmyshell 0.2.22__tar.gz → 0.2.24__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (28) hide show
  1. {xmyshell-0.2.22/xmyshell.egg-info → xmyshell-0.2.24}/PKG-INFO +279 -22
  2. {xmyshell-0.2.22 → xmyshell-0.2.24}/README.md +278 -21
  3. {xmyshell-0.2.22 → xmyshell-0.2.24}/pyproject.toml +1 -1
  4. {xmyshell-0.2.22 → xmyshell-0.2.24}/xmyshell/__main__.py +1 -1
  5. {xmyshell-0.2.22 → xmyshell-0.2.24}/xmyshell/completer.py +3 -5
  6. {xmyshell-0.2.22 → xmyshell-0.2.24}/xmyshell/data/commands.json +1347 -0
  7. {xmyshell-0.2.22 → xmyshell-0.2.24}/xmyshell/kernel.py +9 -4
  8. {xmyshell-0.2.22 → xmyshell-0.2.24}/xmyshell/keybindings.py +2 -2
  9. {xmyshell-0.2.22 → xmyshell-0.2.24/xmyshell.egg-info}/PKG-INFO +279 -22
  10. {xmyshell-0.2.22 → xmyshell-0.2.24}/LICENSE +0 -0
  11. {xmyshell-0.2.22 → xmyshell-0.2.24}/setup.cfg +0 -0
  12. {xmyshell-0.2.22 → xmyshell-0.2.24}/xmyshell/__init__.py +0 -0
  13. {xmyshell-0.2.22 → xmyshell-0.2.24}/xmyshell/environment.py +0 -0
  14. {xmyshell-0.2.22 → xmyshell-0.2.24}/xmyshell/init.py +0 -0
  15. {xmyshell-0.2.22 → xmyshell-0.2.24}/xmyshell/injection.py +0 -0
  16. {xmyshell-0.2.22 → xmyshell-0.2.24}/xmyshell/main.py +0 -0
  17. {xmyshell-0.2.22 → xmyshell-0.2.24}/xmyshell/meta.py +0 -0
  18. {xmyshell-0.2.22 → xmyshell-0.2.24}/xmyshell/stubs/__init__.py +0 -0
  19. {xmyshell-0.2.22 → xmyshell-0.2.24}/xmyshell/stubs/__init__.pyi +0 -0
  20. {xmyshell-0.2.22 → xmyshell-0.2.24}/xmyshell/stubs/py.typed +0 -0
  21. {xmyshell-0.2.22 → xmyshell-0.2.24}/xmyshell/themes.py +0 -0
  22. {xmyshell-0.2.22 → xmyshell-0.2.24}/xmyshell/update.py +0 -0
  23. {xmyshell-0.2.22 → xmyshell-0.2.24}/xmyshell/utils.py +0 -0
  24. {xmyshell-0.2.22 → xmyshell-0.2.24}/xmyshell.egg-info/SOURCES.txt +0 -0
  25. {xmyshell-0.2.22 → xmyshell-0.2.24}/xmyshell.egg-info/dependency_links.txt +0 -0
  26. {xmyshell-0.2.22 → xmyshell-0.2.24}/xmyshell.egg-info/entry_points.txt +0 -0
  27. {xmyshell-0.2.22 → xmyshell-0.2.24}/xmyshell.egg-info/requires.txt +0 -0
  28. {xmyshell-0.2.22 → xmyshell-0.2.24}/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.22
3
+ Version: 0.2.24
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
- [~] $ pyexec
132
- ......
133
- ......def foo():
134
- ...... print("Hello!")
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.