xmyshell 0.2.21__tar.gz → 0.2.22__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.21/xmyshell.egg-info → xmyshell-0.2.22}/PKG-INFO +1 -1
  2. {xmyshell-0.2.21 → xmyshell-0.2.22}/pyproject.toml +1 -1
  3. {xmyshell-0.2.21 → xmyshell-0.2.22}/xmyshell/completer.py +33 -21
  4. {xmyshell-0.2.21 → xmyshell-0.2.22}/xmyshell/keybindings.py +3 -3
  5. {xmyshell-0.2.21 → xmyshell-0.2.22/xmyshell.egg-info}/PKG-INFO +1 -1
  6. {xmyshell-0.2.21 → xmyshell-0.2.22}/LICENSE +0 -0
  7. {xmyshell-0.2.21 → xmyshell-0.2.22}/README.md +0 -0
  8. {xmyshell-0.2.21 → xmyshell-0.2.22}/setup.cfg +0 -0
  9. {xmyshell-0.2.21 → xmyshell-0.2.22}/xmyshell/__init__.py +0 -0
  10. {xmyshell-0.2.21 → xmyshell-0.2.22}/xmyshell/__main__.py +0 -0
  11. {xmyshell-0.2.21 → xmyshell-0.2.22}/xmyshell/data/commands.json +0 -0
  12. {xmyshell-0.2.21 → xmyshell-0.2.22}/xmyshell/environment.py +0 -0
  13. {xmyshell-0.2.21 → xmyshell-0.2.22}/xmyshell/init.py +0 -0
  14. {xmyshell-0.2.21 → xmyshell-0.2.22}/xmyshell/injection.py +0 -0
  15. {xmyshell-0.2.21 → xmyshell-0.2.22}/xmyshell/kernel.py +0 -0
  16. {xmyshell-0.2.21 → xmyshell-0.2.22}/xmyshell/main.py +0 -0
  17. {xmyshell-0.2.21 → xmyshell-0.2.22}/xmyshell/meta.py +0 -0
  18. {xmyshell-0.2.21 → xmyshell-0.2.22}/xmyshell/stubs/__init__.py +0 -0
  19. {xmyshell-0.2.21 → xmyshell-0.2.22}/xmyshell/stubs/__init__.pyi +0 -0
  20. {xmyshell-0.2.21 → xmyshell-0.2.22}/xmyshell/stubs/py.typed +0 -0
  21. {xmyshell-0.2.21 → xmyshell-0.2.22}/xmyshell/themes.py +0 -0
  22. {xmyshell-0.2.21 → xmyshell-0.2.22}/xmyshell/update.py +0 -0
  23. {xmyshell-0.2.21 → xmyshell-0.2.22}/xmyshell/utils.py +0 -0
  24. {xmyshell-0.2.21 → xmyshell-0.2.22}/xmyshell.egg-info/SOURCES.txt +0 -0
  25. {xmyshell-0.2.21 → xmyshell-0.2.22}/xmyshell.egg-info/dependency_links.txt +0 -0
  26. {xmyshell-0.2.21 → xmyshell-0.2.22}/xmyshell.egg-info/entry_points.txt +0 -0
  27. {xmyshell-0.2.21 → xmyshell-0.2.22}/xmyshell.egg-info/requires.txt +0 -0
  28. {xmyshell-0.2.21 → xmyshell-0.2.22}/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.21
3
+ Version: 0.2.22
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
@@ -1,6 +1,6 @@
1
1
  [project]
2
2
  name = "xmyshell"
3
- version = "0.2.21"
3
+ version = "0.2.22"
4
4
  description = "XmyShell is a shell-like tool built on top of prompt_toolkit which provides a persistent Python runtime."
5
5
  readme = "README.md"
6
6
  requires-python = ">=3.12"
@@ -122,7 +122,7 @@ class ShellCompleter(Completer):
122
122
  def _path_completions(self, text: str, max_results: int = 100, in_string: bool=False):
123
123
  if text and text[-1] in whitespace: return
124
124
 
125
- def last_token_raw(text: str) -> str:
125
+ def last_token_raw(text: str) -> tuple[str, bool]:
126
126
  quote = None
127
127
  start = 0
128
128
  i = 0
@@ -141,26 +141,38 @@ class ShellCompleter(Completer):
141
141
  elif ch == "\\":
142
142
  i += 1
143
143
  i += 1
144
- return text[start:]
145
-
146
- def start_pos(text: str, prefix: str) -> int:
147
- original_len = len(text)
148
- if text and text[-1] in ("'", '"') and not text.endswith(prefix):
149
- text = text[:-1]
150
- if not prefix or not text.endswith(prefix):
151
- return -len(prefix)
152
- start = len(text) - len(prefix)
153
- if start > 0 and text[start - 1] in ("'", '"'):
154
- start -= 1
155
- return start - original_len
156
-
157
- last = last_token_raw(text)
158
- in_string = in_string or last.startswith('"') or last.startswith("'")
159
- last = last.lstrip('"\'')
144
+ return text[start:], quote is not None
145
+
146
+ def split_lenient(s: str) -> list[str] | None:
147
+ try:
148
+ return shlex.split(s)
149
+ except ValueError:
150
+ pass
151
+ quote = None
152
+ i = 0
153
+ while i < len(s):
154
+ ch = s[i]
155
+ if quote:
156
+ if ch == quote: quote = None
157
+ elif ch == '\\' and quote == '"': i += 1
158
+ else:
159
+ if ch in ('"', "'"): quote = ch
160
+ elif ch == '\\': i += 1
161
+ i += 1
162
+ if quote:
163
+ try:
164
+ return shlex.split(s + quote)
165
+ except ValueError:
166
+ pass
167
+ return None
168
+
169
+ last, still_in = last_token_raw(text)
170
+ in_string = in_string or still_in
160
171
  if last == '~': return # don't remove this
161
- try:
162
- path = os.path.expanduser(shlex.split(last)[0])
163
- except (ValueError, IndexError):
172
+ parts = split_lenient(last)
173
+ if parts:
174
+ path = os.path.expanduser(parts[0])
175
+ else:
164
176
  path = os.path.expanduser(last)
165
177
  dirname = os.path.dirname(path) or "."
166
178
  prefix = os.path.basename(path).strip('"\'')
@@ -183,7 +195,7 @@ class ShellCompleter(Completer):
183
195
  yield Completion(
184
196
  name,
185
197
  display=truncate(item, MAX_DISPLAY_LEN),
186
- start_position=start_pos(text, prefix),
198
+ start_position=-len(prefix),
187
199
  display_meta="directory" if is_dir else "file",
188
200
  )
189
201
  except OSError:
@@ -375,7 +375,7 @@ def _(event: KeyPressEvent) -> None:
375
375
  buffer.insert_text(" ")
376
376
 
377
377
  @bindings.add(Keys.Enter)
378
- def handle_enter(event):
378
+ def _(event: KeyPressEvent):
379
379
  buffer = event.current_buffer
380
380
  current_line = buffer.document.current_line_before_cursor
381
381
 
@@ -386,6 +386,6 @@ def handle_enter(event):
386
386
  else:
387
387
  buffer.validate_and_handle()
388
388
 
389
- @bindings.add("escape", filter=has_completions, eager=True)
390
- def cancel_completion(event):
389
+ @bindings.add(Keys.Escape, filter=has_completions, eager=True)
390
+ def _(event: KeyPressEvent):
391
391
  event.current_buffer.cancel_completion()
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: xmyshell
3
- Version: 0.2.21
3
+ Version: 0.2.22
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
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