nercone-shell 0.3.8__tar.gz → 0.4.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.3.8
3
+ Version: 0.4.1
4
4
  Summary: Modern shell for Developers
5
5
  Author: Nercone
6
6
  Author-email: Nercone <nercone@diamondgotcat.net>
@@ -68,7 +68,7 @@ nersh
68
68
  ```
69
69
 
70
70
  ## Configuration
71
- The configuration file is usually located at `~/.nercone/nercone-shell/config.json`.
71
+ The configuration file is usually located at `~/.nersh/config.json`.
72
72
  If the file does not exist when Nersh starts, it will be automatically created.
73
73
 
74
74
  The following is the default configuration file:
@@ -81,7 +81,7 @@ The following is the default configuration file:
81
81
  "SHELL": "None"
82
82
  },
83
83
  "autoruns": [
84
- "<path to home directory>/.nercone/nercone-shell/autostart.sh"
84
+ "<path to home directory>/.nersh/autostart.sh"
85
85
  ]
86
86
  },
87
87
  "compatibility": {
@@ -53,7 +53,7 @@ nersh
53
53
  ```
54
54
 
55
55
  ## Configuration
56
- The configuration file is usually located at `~/.nercone/nercone-shell/config.json`.
56
+ The configuration file is usually located at `~/.nersh/config.json`.
57
57
  If the file does not exist when Nersh starts, it will be automatically created.
58
58
 
59
59
  The following is the default configuration file:
@@ -66,7 +66,7 @@ The following is the default configuration file:
66
66
  "SHELL": "None"
67
67
  },
68
68
  "autoruns": [
69
- "<path to home directory>/.nercone/nercone-shell/autostart.sh"
69
+ "<path to home directory>/.nersh/autostart.sh"
70
70
  ]
71
71
  },
72
72
  "compatibility": {
@@ -4,7 +4,7 @@ build-backend = "uv_build"
4
4
 
5
5
  [project]
6
6
  name = "nercone-shell"
7
- version = "0.3.8"
7
+ version = "0.4.1"
8
8
  description = "Modern shell for Developers"
9
9
  readme = { file = "README.md", content-type = "text/markdown" }
10
10
  authors = [
@@ -30,8 +30,8 @@ try:
30
30
  except PackageNotFoundError:
31
31
  VERSION: str = "(version unknown)"
32
32
  ENVIRONMENT: dict = {}
33
- NERSH_AUTORUN: str = os.environ.get("NERSH_AUTORUN", None)
34
- NERSH_PATH = Path(os.environ.get("NERSH_PATH", str(Path(Path("~").expanduser(), ".nercone", "nercone-shell"))))
33
+ NERSH_AUTORUN: str | None = os.environ.get("NERSH_AUTORUN", None)
34
+ NERSH_PATH = Path(os.environ.get("NERSH_PATH", str(Path(Path("~").expanduser(), ".nersh"))))
35
35
  NERSH_HISTORY_PATH = Path(os.environ.get("NERSH_HISTORY_PATH", str(Path(NERSH_PATH, "history.txt"))))
36
36
  NERSH_CONFIG: dict = {}
37
37
  NERSH_CONFIG_PATH = Path(os.environ.get("NERSH_CONFIG_PATH", str(Path(NERSH_PATH, "config.json"))))
@@ -40,10 +40,10 @@ NERSH_CONFIG_DEFAULT: dict = {
40
40
  "show_version": True,
41
41
  "accent_color": "blue",
42
42
  "override_env": {
43
- "SHELL": f"{shutil.which('nersh')}"
43
+ "SHELL": f"{shutil.which('nersh') or 'nersh'}"
44
44
  },
45
- "autoruns": [
46
- f"{Path(NERSH_PATH, 'autostart.sh')}"
45
+ "autorun": [
46
+ f"{Path(NERSH_PATH, 'autorun.sh')}"
47
47
  ]
48
48
  },
49
49
  "compatibility": {
@@ -166,7 +166,7 @@ def show_version():
166
166
 
167
167
  def reset():
168
168
  global ENVIRONMENT, NERSH_CONFIG
169
- ENVIRONMENT = {"PWD": f"{Path(Path("~").expanduser())}"}
169
+ ENVIRONMENT = {"PWD": f"{Path('~').expanduser()}"}
170
170
  NERSH_CONFIG = {}
171
171
  reload()
172
172
 
@@ -186,7 +186,7 @@ def load_config() -> dict:
186
186
  f.write(json.dumps(NERSH_CONFIG_DEFAULT, indent=4) + "\n")
187
187
  with NERSH_CONFIG_PATH.open("r") as f:
188
188
  NERSH_CONFIG |= json.loads(f.read())
189
- for p in NERSH_CONFIG.get("customization", {}).get("autoruns", []):
189
+ for p in NERSH_CONFIG.get("customization", {}).get("autorun", []):
190
190
  if not Path(p).is_file():
191
191
  with Path(p).open("w") as f:
192
192
  f.write("\n")
@@ -202,14 +202,17 @@ def run_line(command: str) -> int:
202
202
  cmd = args[0]
203
203
  if cmd == "version":
204
204
  show_version()
205
+ return 0
205
206
  elif cmd == "reset":
206
207
  reset()
208
+ return 0
207
209
  elif cmd == "reload":
208
210
  reload()
211
+ return 0
209
212
  elif cmd == "cd":
210
213
  target = " ".join(args[1:])
211
214
  if not target:
212
- ENVIRONMENT["PWD"] = f"{Path("~").expanduser()}"
215
+ ENVIRONMENT["PWD"] = f"{Path('~').expanduser()}"
213
216
  target = os.path.expanduser(target)
214
217
  target_path = Path(target)
215
218
  if not target_path.is_absolute():
@@ -218,12 +221,16 @@ def run_line(command: str) -> int:
218
221
  resolved_path = target_path.resolve()
219
222
  if resolved_path.is_dir():
220
223
  ENVIRONMENT["PWD"] = str(resolved_path)
224
+ return 0
221
225
  elif resolved_path.exists():
222
226
  print(f"Not a directory: {target}")
227
+ return 1
223
228
  else:
224
229
  print(f"Not exist: {target}")
230
+ return 1
225
231
  except FileNotFoundError:
226
232
  print(f"Not exist: {target}")
233
+ return 1
227
234
  elif cmd == "export":
228
235
  content = command.strip()[6:].strip()
229
236
  if "=" in content:
@@ -235,6 +242,7 @@ def run_line(command: str) -> int:
235
242
  if not content:
236
243
  for k, v in ENVIRONMENT.items():
237
244
  print(f"{k}={v}")
245
+ return 0
238
246
  elif cmd == "source" or cmd == ".":
239
247
  if len(args) < 2:
240
248
  print(f"{cmd}: filename argument required")
@@ -242,7 +250,7 @@ def run_line(command: str) -> int:
242
250
  target = args[1]
243
251
  target_path = Path(os.path.expanduser(target))
244
252
  if not target_path.is_absolute():
245
- target_path = Path(ENVIRONMENT.get("PWD")) / target_path
253
+ target_path = Path(ENVIRONMENT.get("PWD", Path("~").expanduser())) / target_path
246
254
  if target_path.is_file():
247
255
  try:
248
256
  with target_path.open("r") as f:
@@ -255,6 +263,7 @@ def run_line(command: str) -> int:
255
263
  else:
256
264
  print(f"nersh: {target}: No such file")
257
265
  return 1
266
+ return 0
258
267
  elif cmd == "exit":
259
268
  if NERSH_CONFIG.get("experimental", {}).get("command_history", False):
260
269
  readline.write_history_file(str(NERSH_HISTORY_PATH))
@@ -270,18 +279,18 @@ def run_script(script: str):
270
279
  for line in script.split('\n'):
271
280
  run_line(line)
272
281
 
273
- def main() -> int:
282
+ def main():
274
283
  reset()
275
284
  completer = NershCompleter()
276
285
  readline.set_completer(completer.complete)
277
- if 'libedit' in readline.__doc__:
286
+ if 'libedit' in str(readline.__doc__):
278
287
  readline.parse_and_bind("bind ^I rl_complete")
279
288
  else:
280
289
  readline.parse_and_bind("tab: complete")
281
290
  readline.set_completer_delims(' \t\n;')
282
291
  if NERSH_CONFIG.get("customization", {}).get("show_version", True):
283
292
  show_version()
284
- for p in NERSH_CONFIG.get("customization", {}).get("autoruns", []):
293
+ for p in NERSH_CONFIG.get("customization", {}).get("autorun", []):
285
294
  if Path(p).is_file():
286
295
  with Path(p).open("r") as f:
287
296
  run_script(f.read())
@@ -297,9 +306,9 @@ def main() -> int:
297
306
  try:
298
307
  RL_PROMPT_START_IGNORE = "\001" if NERSH_CONFIG.get("compatibility", {}).get("report_invisible_characters", False) else ""
299
308
  RL_PROMPT_END_IGNORE = "\002" if NERSH_CONFIG.get("compatibility", {}).get("report_invisible_characters", False) else ""
300
- color_accent = f"{RL_PROMPT_START_IGNORE}{ModernColor.color(NERSH_CONFIG.get('customization', {}).get('accent_color', 'blue'))}{RL_PROMPT_END_IGNORE}"
301
- color_reset = f"{RL_PROMPT_START_IGNORE}{ModernColor.color('reset')}{RL_PROMPT_END_IGNORE}"
302
- run_line(input(f"{color_accent}{getpass.getuser().lower()}{color_reset}@{hostname.lower()} {color_accent}{shorten_path(ENVIRONMENT.get('PWD', f'{Path('~').expanduser()}'))}{color_reset}> "))
309
+ color_accent = f"{RL_PROMPT_START_IGNORE}{ModernColor.from_name(NERSH_CONFIG.get('customization', {}).get('accent_color', 'blue'))}{RL_PROMPT_END_IGNORE}"
310
+ color_reset = f"{RL_PROMPT_START_IGNORE}{ModernColor.from_name('reset')}{RL_PROMPT_END_IGNORE}"
311
+ run_line(input(f"{color_accent}{getpass.getuser().lower()}{color_reset}@{hostname.lower()} {color_accent}{shorten_path(ENVIRONMENT.get('PWD', str(Path('~').expanduser())))}{color_reset}> "))
303
312
  if not NERSH_CONFIG.get("experimental", {}).get("command_history", False):
304
313
  readline.clear_history()
305
314
  except KeyboardInterrupt: