nercone-shell 0.1.0__tar.gz → 0.2.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.
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.3
2
2
  Name: nercone-shell
3
- Version: 0.1.0
3
+ Version: 0.2.1
4
4
  Summary: Modern shell for Developers
5
5
  Author: Nercone
6
6
  Author-email: Nercone <nercone@diamondgotcat.net>
@@ -8,7 +8,6 @@ License: MIT
8
8
  Classifier: Programming Language :: Python :: 3
9
9
  Classifier: License :: OSI Approved :: MIT License
10
10
  Classifier: Operating System :: OS Independent
11
- Requires-Dist: nercone-modern
12
11
  Requires-Python: >=3.8
13
12
  Description-Content-Type: text/markdown
14
13
 
@@ -4,7 +4,7 @@ build-backend = "uv_build"
4
4
 
5
5
  [project]
6
6
  name = "nercone-shell"
7
- version = "0.1.0"
7
+ version = "0.2.1"
8
8
  description = "Modern shell for Developers"
9
9
  readme = { file = "README.md", content-type = "text/markdown" }
10
10
  authors = [
@@ -12,9 +12,7 @@ authors = [
12
12
  ]
13
13
  license = { text = "MIT" }
14
14
  requires-python = ">=3.8"
15
- dependencies = [
16
- "nercone-modern"
17
- ]
15
+ dependencies = []
18
16
  classifiers = [
19
17
  "Programming Language :: Python :: 3",
20
18
  "License :: OSI Approved :: MIT License",
@@ -1,13 +1,14 @@
1
1
  #!/usr/bin/env python3
2
2
 
3
3
  # -- nercone-shell ---------------------------------------------- #
4
- # __main__.py on nercone-shell #
4
+ # __main__.py on Nersh #
5
5
  # Made by DiamondGotCat, Licensed under MIT License #
6
6
  # Copyright (c) 2025 DiamondGotCat #
7
7
  # ---------------------------------------------- DiamondGotCat -- #
8
8
 
9
9
  import os
10
10
  import sys
11
+ import re
11
12
  import json
12
13
  import glob
13
14
  import shutil
@@ -33,9 +34,6 @@ NERSH_CONFIG_DEFAULT: dict = {
33
34
  "override_env": {
34
35
  "SHELL": f"{shutil.which('nersh')}"
35
36
  },
36
- "history": {
37
- "path": f"{Path(NERSH_PATH, 'history.txt')}"
38
- },
39
37
  "autoruns": [
40
38
  f"{Path(NERSH_PATH, 'autostart.sh')}"
41
39
  ]
@@ -77,7 +75,7 @@ class NershCompleter:
77
75
  results.add(filename + " ")
78
76
  except (PermissionError, OSError):
79
77
  continue
80
-
78
+
81
79
  return sorted(list(results))
82
80
 
83
81
  def _complete_path(self, text):
@@ -160,7 +158,7 @@ def reload():
160
158
  ENVIRONMENT |= os.environ
161
159
  ENVIRONMENT |= NERSH_CONFIG.get("override_env", {})
162
160
 
163
- def load_config(filepath: str | Path = NERSH_CONFIG_PATH) -> dict:
161
+ def load_config() -> dict:
164
162
  global NERSH_CONFIG
165
163
  NERSH_PATH.mkdir(parents=True, exist_ok=True)
166
164
  if not NERSH_CONFIG_PATH.is_file():
@@ -175,15 +173,21 @@ def load_config(filepath: str | Path = NERSH_CONFIG_PATH) -> dict:
175
173
  return NERSH_CONFIG
176
174
 
177
175
  def run_line(command: str) -> int:
176
+ def expand_vars(match):
177
+ key = match.group(1) or match.group(2)
178
+ return ENVIRONMENT.get(key, "")
179
+ if command.strip():
180
+ command = re.sub(r'\$(\w+)|\$\{(\w+)\}', expand_vars, command)
178
181
  args = command.strip().split(" ")
179
- if args[0] == "cd":
182
+ cmd = args[0]
183
+ if cmd == "version":
184
+ print(f"Nersh v{VERSION}")
185
+ elif cmd == "cd":
180
186
  target = " ".join(args[1:])
181
187
  if not target:
182
188
  ENVIRONMENT["PWD"] = f"{Path("~").expanduser()}"
183
-
184
189
  target = os.path.expanduser(target)
185
190
  target_path = Path(target)
186
-
187
191
  if not target_path.is_absolute():
188
192
  target_path = Path(ENVIRONMENT["PWD"]) / target_path
189
193
  try:
@@ -196,7 +200,38 @@ def run_line(command: str) -> int:
196
200
  print(f"Not exist: {target}")
197
201
  except FileNotFoundError:
198
202
  print(f"Not exist: {target}")
199
- elif args[0] == "exit":
203
+ elif cmd == "export":
204
+ content = command.strip()[6:].strip()
205
+ if "=" in content:
206
+ key, value = content.split("=", 1)
207
+ if len(value) >= 2 and ((value[0] == '"' and value[-1] == '"') or (value[0] == "'" and value[-1] == "'")):
208
+ value = value[1:-1]
209
+ ENVIRONMENT[key] = value
210
+ else:
211
+ if not content:
212
+ for k, v in ENVIRONMENT.items():
213
+ print(f"{k}={v}")
214
+ elif cmd == "source" or cmd == ".":
215
+ if len(args) < 2:
216
+ print(f"{cmd}: filename argument required")
217
+ return 1
218
+ target = args[1]
219
+ target_path = Path(os.path.expanduser(target))
220
+ if not target_path.is_absolute():
221
+ target_path = Path(ENVIRONMENT.get("PWD")) / target_path
222
+ if target_path.is_file():
223
+ try:
224
+ with target_path.open("r") as f:
225
+ for line in f:
226
+ if line.strip() and not line.strip().startswith("#"):
227
+ run_line(line)
228
+ except Exception as e:
229
+ print(f"nersh: {e}")
230
+ return 1
231
+ else:
232
+ print(f"nersh: {target}: No such file")
233
+ return 1
234
+ elif cmd == "exit":
200
235
  readline.write_history_file(str(NERSH_HISTORY_PATH))
201
236
  try:
202
237
  raise SystemExit(int(args[1]))
@@ -219,6 +254,14 @@ def main() -> int:
219
254
  else:
220
255
  readline.parse_and_bind("tab: complete")
221
256
  readline.set_completer_delims(' \t\n;')
257
+ for p in NERSH_CONFIG.get("autoruns"):
258
+ if Path(p).is_file():
259
+ with Path(p).open("r") as f:
260
+ run_script(f.read())
261
+ elif Path(p).exists():
262
+ print(f"(autorun failed) Not a file: {p}")
263
+ else:
264
+ print(f"(autorun failed) Not exist: {p}")
222
265
  if NERSH_AUTORUN:
223
266
  run_script(NERSH_AUTORUN)
224
267
  if NERSH_HISTORY_PATH.is_file():
File without changes