xmyshell 0.2.0__tar.gz → 0.2.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.
- {xmyshell-0.2.0/xmyshell.egg-info → xmyshell-0.2.2}/PKG-INFO +5 -1
- {xmyshell-0.2.0 → xmyshell-0.2.2}/README.md +4 -0
- {xmyshell-0.2.0 → xmyshell-0.2.2}/pyproject.toml +1 -1
- {xmyshell-0.2.0 → xmyshell-0.2.2}/xmyshell/completer.py +30 -11
- {xmyshell-0.2.0 → xmyshell-0.2.2}/xmyshell/environment.py +7 -2
- {xmyshell-0.2.0 → xmyshell-0.2.2}/xmyshell/kernel.py +15 -8
- {xmyshell-0.2.0 → xmyshell-0.2.2}/xmyshell/meta.py +2 -0
- {xmyshell-0.2.0 → xmyshell-0.2.2/xmyshell.egg-info}/PKG-INFO +5 -1
- {xmyshell-0.2.0 → xmyshell-0.2.2}/LICENSE +0 -0
- {xmyshell-0.2.0 → xmyshell-0.2.2}/setup.cfg +0 -0
- {xmyshell-0.2.0 → xmyshell-0.2.2}/xmyshell/__init__.py +0 -0
- {xmyshell-0.2.0 → xmyshell-0.2.2}/xmyshell/__main__.py +0 -0
- {xmyshell-0.2.0 → xmyshell-0.2.2}/xmyshell/data/commands.json +0 -0
- {xmyshell-0.2.0 → xmyshell-0.2.2}/xmyshell/init.py +0 -0
- {xmyshell-0.2.0 → xmyshell-0.2.2}/xmyshell/keybindings.py +0 -0
- {xmyshell-0.2.0 → xmyshell-0.2.2}/xmyshell/lexer.py +0 -0
- {xmyshell-0.2.0 → xmyshell-0.2.2}/xmyshell/main.py +0 -0
- {xmyshell-0.2.0 → xmyshell-0.2.2}/xmyshell/themes.py +0 -0
- {xmyshell-0.2.0 → xmyshell-0.2.2}/xmyshell/update.py +0 -0
- {xmyshell-0.2.0 → xmyshell-0.2.2}/xmyshell/utils.py +0 -0
- {xmyshell-0.2.0 → xmyshell-0.2.2}/xmyshell.egg-info/SOURCES.txt +0 -0
- {xmyshell-0.2.0 → xmyshell-0.2.2}/xmyshell.egg-info/dependency_links.txt +0 -0
- {xmyshell-0.2.0 → xmyshell-0.2.2}/xmyshell.egg-info/entry_points.txt +0 -0
- {xmyshell-0.2.0 → xmyshell-0.2.2}/xmyshell.egg-info/requires.txt +0 -0
- {xmyshell-0.2.0 → xmyshell-0.2.2}/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.2
|
|
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
|
|
@@ -115,6 +115,7 @@ or
|
|
|
115
115
|
- Alias
|
|
116
116
|
```
|
|
117
117
|
❯ alias ll='ls -lh'
|
|
118
|
+
❯ unalias ll
|
|
118
119
|
```
|
|
119
120
|
|
|
120
121
|
- Syntax highlighting via `prompt_toolkit`
|
|
@@ -142,6 +143,9 @@ Shortcut for `open(file).read()`.
|
|
|
142
143
|
- `alias(altname, target)`
|
|
143
144
|
Same as the command.
|
|
144
145
|
|
|
146
|
+
- `unalias(altname)`
|
|
147
|
+
Same as the command.
|
|
148
|
+
|
|
145
149
|
|
|
146
150
|
### Reserved global varibles
|
|
147
151
|
- `exit_code`
|
|
@@ -105,6 +105,7 @@ or
|
|
|
105
105
|
- Alias
|
|
106
106
|
```
|
|
107
107
|
❯ alias ll='ls -lh'
|
|
108
|
+
❯ unalias ll
|
|
108
109
|
```
|
|
109
110
|
|
|
110
111
|
- Syntax highlighting via `prompt_toolkit`
|
|
@@ -132,6 +133,9 @@ Shortcut for `open(file).read()`.
|
|
|
132
133
|
- `alias(altname, target)`
|
|
133
134
|
Same as the command.
|
|
134
135
|
|
|
136
|
+
- `unalias(altname)`
|
|
137
|
+
Same as the command.
|
|
138
|
+
|
|
135
139
|
|
|
136
140
|
### Reserved global varibles
|
|
137
141
|
- `exit_code`
|
|
@@ -8,7 +8,7 @@ import pkgutil
|
|
|
8
8
|
from string import whitespace
|
|
9
9
|
from prompt_toolkit.completion import Completer, Completion
|
|
10
10
|
from prompt_toolkit.document import Document
|
|
11
|
-
from .environment import namespace
|
|
11
|
+
from .environment import namespace, aliases
|
|
12
12
|
from .utils import truncate
|
|
13
13
|
from pathlib import Path
|
|
14
14
|
|
|
@@ -16,7 +16,8 @@ MAX_DISPLAY_LEN = 24
|
|
|
16
16
|
MAX_META_LEN = 12
|
|
17
17
|
|
|
18
18
|
BUILTINS = ("cd", "cp", "cat", "echo", "exit", "import", "ls", "print", "pyexec", "pwd", "source",
|
|
19
|
-
"clear", "grep", "find", "from", "mkdir", "rm", "reload", "mv", "help",
|
|
19
|
+
"clear", "grep", "find", "from", "mkdir", "rm", "reload", "mv", "help",
|
|
20
|
+
"update", "alias", "unalias")
|
|
20
21
|
|
|
21
22
|
COMMON = (
|
|
22
23
|
"python", "python3", "pip", "pip3", "git", "conda", "uv",
|
|
@@ -312,6 +313,28 @@ class ShellCompleter(Completer):
|
|
|
312
313
|
display_meta="flag",
|
|
313
314
|
)
|
|
314
315
|
|
|
316
|
+
def _command_completion(self, text):
|
|
317
|
+
for cmd in self._get_commands():
|
|
318
|
+
if cmd in aliases: continue
|
|
319
|
+
if cmd.startswith(text):
|
|
320
|
+
meta = "command" if cmd in BUILTINS else "program"
|
|
321
|
+
yield Completion(
|
|
322
|
+
cmd,
|
|
323
|
+
start_position=-len(text),
|
|
324
|
+
display=truncate(cmd, MAX_DISPLAY_LEN),
|
|
325
|
+
display_meta=meta,
|
|
326
|
+
)
|
|
327
|
+
|
|
328
|
+
def _alias_completion(self, text):
|
|
329
|
+
for alias in aliases.keys():
|
|
330
|
+
if alias.startswith(text):
|
|
331
|
+
yield Completion(
|
|
332
|
+
alias,
|
|
333
|
+
start_position=-len(text),
|
|
334
|
+
display=truncate(alias, MAX_DISPLAY_LEN),
|
|
335
|
+
display_meta="alias",
|
|
336
|
+
)
|
|
337
|
+
|
|
315
338
|
def get_completions(self, document: Document, complete_event):
|
|
316
339
|
text = document.text_before_cursor
|
|
317
340
|
if "=>" in text: return
|
|
@@ -328,15 +351,8 @@ class ShellCompleter(Completer):
|
|
|
328
351
|
if " " not in lstripped:
|
|
329
352
|
if len(lstripped) < 1:
|
|
330
353
|
return
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
meta = "command" if cmd in BUILTINS else "program"
|
|
334
|
-
yield Completion(
|
|
335
|
-
cmd,
|
|
336
|
-
start_position=-len(lstripped),
|
|
337
|
-
display=truncate(cmd, MAX_DISPLAY_LEN),
|
|
338
|
-
display_meta=meta,
|
|
339
|
-
)
|
|
354
|
+
yield from self._alias_completion(lstripped)
|
|
355
|
+
yield from self._command_completion(lstripped)
|
|
340
356
|
|
|
341
357
|
# special built-ins
|
|
342
358
|
parts = lstripped.split()
|
|
@@ -346,6 +362,9 @@ class ShellCompleter(Completer):
|
|
|
346
362
|
param_text = lstripped[len(cmd):].lstrip()
|
|
347
363
|
yield from self._python_completion(param_text)
|
|
348
364
|
return
|
|
365
|
+
if cmd == "unalias":
|
|
366
|
+
param_text = lstripped[len(cmd):].lstrip()
|
|
367
|
+
yield from self._alias_completion(param_text)
|
|
349
368
|
if cmd == "from":
|
|
350
369
|
if not lstripped.endswith(parts[-1]):
|
|
351
370
|
parts.append("")
|
|
@@ -11,8 +11,12 @@ namespace: dict[str, Any] = {}
|
|
|
11
11
|
aliases: dict[str, str] = {}
|
|
12
12
|
init_environ: dict[str, str] = dict(os.environ)
|
|
13
13
|
|
|
14
|
-
|
|
15
|
-
|
|
14
|
+
|
|
15
|
+
def xmyshell_alias(altname: str, target: str) -> None:
|
|
16
|
+
aliases.update({altname: target})
|
|
17
|
+
|
|
18
|
+
def xmyshell_unalias(altname: str) -> None:
|
|
19
|
+
aliases.pop(altname)
|
|
16
20
|
|
|
17
21
|
|
|
18
22
|
_init_namespace: dict[str, Any] = {
|
|
@@ -29,6 +33,7 @@ _init_namespace: dict[str, Any] = {
|
|
|
29
33
|
"basename": os.path.basename,
|
|
30
34
|
"cat": xmyshell_cat,
|
|
31
35
|
"alias": xmyshell_alias,
|
|
36
|
+
"unalias": xmyshell_unalias,
|
|
32
37
|
"HOME_DIR": HOME_DIR,
|
|
33
38
|
"PROFILE": f"{HOME_DIR}/.xmyshell/config.py",
|
|
34
39
|
"exit_code": 0,
|
|
@@ -4,7 +4,7 @@ import sys
|
|
|
4
4
|
import runpy
|
|
5
5
|
import subprocess
|
|
6
6
|
import shlex
|
|
7
|
-
from .environment import namespace, aliases
|
|
7
|
+
from .environment import namespace, aliases, xmyshell_alias, xmyshell_unalias
|
|
8
8
|
from .utils import pywarning, pyerror, getcwd
|
|
9
9
|
from .meta import HELP_MESSAGE
|
|
10
10
|
|
|
@@ -128,14 +128,22 @@ def xmyshell_raw_command(cmd_line: str) -> int | None:
|
|
|
128
128
|
pyerror("export: missing code")
|
|
129
129
|
return -1
|
|
130
130
|
try:
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
131
|
+
altname, alias_target = code.split('=', 1)
|
|
132
|
+
altname = altname.strip()
|
|
133
|
+
xmyshell_alias(altname, eval(alias_target, namespace, {}))
|
|
134
134
|
return 0
|
|
135
135
|
except Exception as e:
|
|
136
136
|
pyerror(f"{type(e).__name__}: {e}")
|
|
137
137
|
return -1
|
|
138
138
|
|
|
139
|
+
case "unalias":
|
|
140
|
+
name: str = cmd_line[len(command):].strip()
|
|
141
|
+
if not name:
|
|
142
|
+
pyerror("export: missing name")
|
|
143
|
+
return -1
|
|
144
|
+
xmyshell_unalias(name)
|
|
145
|
+
return 0
|
|
146
|
+
|
|
139
147
|
case "print":
|
|
140
148
|
expr = cmd_line[len(command):].strip()
|
|
141
149
|
if not expr:
|
|
@@ -154,12 +162,11 @@ def xmyshell_raw_command(cmd_line: str) -> int | None:
|
|
|
154
162
|
return 0
|
|
155
163
|
|
|
156
164
|
case "update":
|
|
157
|
-
|
|
158
|
-
subprocess.run(
|
|
165
|
+
returncode = subprocess.run(
|
|
159
166
|
[sys.executable, "-m", "xmyshell.update"]
|
|
160
167
|
+ (args[1:] if len(args) > 1 else [])
|
|
161
|
-
)
|
|
162
|
-
return
|
|
168
|
+
).returncode
|
|
169
|
+
return returncode
|
|
163
170
|
|
|
164
171
|
case "help":
|
|
165
172
|
print(HELP_MESSAGE)
|
|
@@ -30,6 +30,7 @@ Built-in Commands:
|
|
|
30
30
|
pwd Print working directory.
|
|
31
31
|
clear Clear the terminal screen.
|
|
32
32
|
alias altname=<cmd> Create an alias command.
|
|
33
|
+
unalias altname Remove an alias command.
|
|
33
34
|
exit Exit XmyShell.
|
|
34
35
|
|
|
35
36
|
Inline Python:
|
|
@@ -51,6 +52,7 @@ Helper Functions:
|
|
|
51
52
|
basename(p) - final component of path
|
|
52
53
|
cat(file) - Shortcut for open(file).read().
|
|
53
54
|
alias(altname, cmd) - Same as the command.
|
|
55
|
+
unalias(altname) - Same as the command.
|
|
54
56
|
|
|
55
57
|
Built-in variables:
|
|
56
58
|
exit_code - The exit code of the last command.
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.4
|
|
2
2
|
Name: xmyshell
|
|
3
|
-
Version: 0.2.
|
|
3
|
+
Version: 0.2.2
|
|
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
|
|
@@ -115,6 +115,7 @@ or
|
|
|
115
115
|
- Alias
|
|
116
116
|
```
|
|
117
117
|
❯ alias ll='ls -lh'
|
|
118
|
+
❯ unalias ll
|
|
118
119
|
```
|
|
119
120
|
|
|
120
121
|
- Syntax highlighting via `prompt_toolkit`
|
|
@@ -142,6 +143,9 @@ Shortcut for `open(file).read()`.
|
|
|
142
143
|
- `alias(altname, target)`
|
|
143
144
|
Same as the command.
|
|
144
145
|
|
|
146
|
+
- `unalias(altname)`
|
|
147
|
+
Same as the command.
|
|
148
|
+
|
|
145
149
|
|
|
146
150
|
### Reserved global varibles
|
|
147
151
|
- `exit_code`
|
|
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
|