machineconfig 7.57__py3-none-any.whl → 7.79__py3-none-any.whl

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.

Potentially problematic release.


This version of machineconfig might be problematic. Click here for more details.

Files changed (104) hide show
  1. machineconfig/cluster/sessions_managers/utils/maker.py +21 -9
  2. machineconfig/jobs/installer/custom/boxes.py +2 -2
  3. machineconfig/jobs/installer/custom/hx.py +3 -3
  4. machineconfig/jobs/installer/custom_dev/cloudflare_warp_cli.py +23 -0
  5. machineconfig/jobs/installer/custom_dev/dubdb_adbc.py +1 -1
  6. machineconfig/jobs/installer/custom_dev/nerfont_windows_helper.py +1 -1
  7. machineconfig/jobs/installer/custom_dev/sysabc.py +36 -28
  8. machineconfig/jobs/installer/custom_dev/wezterm.py +0 -4
  9. machineconfig/jobs/installer/installer_data.json +127 -25
  10. machineconfig/jobs/installer/package_groups.py +20 -13
  11. machineconfig/profile/create_links_export.py +2 -2
  12. machineconfig/scripts/__init__.py +0 -4
  13. machineconfig/scripts/linux/wrap_mcfg +1 -1
  14. machineconfig/scripts/python/agents.py +22 -17
  15. machineconfig/scripts/python/ai/solutions/copilot/instructions/python/dev.instructions.md +3 -0
  16. machineconfig/scripts/python/croshell.py +22 -17
  17. machineconfig/scripts/python/devops.py +3 -4
  18. machineconfig/scripts/python/devops_navigator.py +0 -4
  19. machineconfig/scripts/python/env_manager/path_manager_tui.py +1 -1
  20. machineconfig/scripts/python/fire_jobs.py +19 -18
  21. machineconfig/scripts/python/ftpx.py +36 -12
  22. machineconfig/scripts/python/helpers/ast_search.py +74 -0
  23. machineconfig/scripts/python/helpers/qr_code.py +166 -0
  24. machineconfig/scripts/python/helpers/repo_rag.py +325 -0
  25. machineconfig/scripts/python/helpers/symantic_search.py +25 -0
  26. machineconfig/scripts/python/helpers_cloud/cloud_copy.py +28 -21
  27. machineconfig/scripts/python/helpers_cloud/cloud_helpers.py +1 -1
  28. machineconfig/scripts/python/helpers_cloud/cloud_mount.py +19 -17
  29. machineconfig/scripts/python/helpers_cloud/cloud_sync.py +8 -7
  30. machineconfig/scripts/python/helpers_croshell/crosh.py +2 -2
  31. machineconfig/scripts/python/helpers_croshell/start_slidev.py +6 -7
  32. machineconfig/scripts/python/helpers_devops/cli_config_dotfile.py +4 -5
  33. machineconfig/scripts/python/helpers_devops/cli_nw.py +88 -7
  34. machineconfig/scripts/python/helpers_devops/cli_self.py +7 -6
  35. machineconfig/scripts/python/helpers_devops/cli_share_file.py +9 -9
  36. machineconfig/scripts/python/helpers_devops/cli_share_server.py +13 -12
  37. machineconfig/scripts/python/helpers_devops/cli_terminal.py +7 -6
  38. machineconfig/scripts/python/helpers_devops/cli_utils.py +2 -73
  39. machineconfig/scripts/python/helpers_devops/devops_backup_retrieve.py +4 -4
  40. machineconfig/scripts/python/helpers_devops/devops_status.py +7 -19
  41. machineconfig/scripts/python/helpers_fire_command/file_wrangler.py +2 -3
  42. machineconfig/scripts/python/helpers_fire_command/fire_jobs_route_helper.py +23 -13
  43. machineconfig/scripts/python/helpers_navigator/command_tree.py +50 -18
  44. machineconfig/scripts/python/helpers_repos/cloud_repo_sync.py +7 -4
  45. machineconfig/scripts/python/helpers_repos/count_lines_frontend.py +1 -1
  46. machineconfig/scripts/python/helpers_repos/entrypoint.py +2 -1
  47. machineconfig/scripts/python/helpers_repos/record.py +2 -1
  48. machineconfig/scripts/python/helpers_sessions/sessions_multiprocess.py +5 -5
  49. machineconfig/scripts/python/helpers_utils/download.py +152 -0
  50. machineconfig/scripts/python/helpers_utils/path.py +81 -31
  51. machineconfig/scripts/python/interactive.py +2 -2
  52. machineconfig/scripts/python/{machineconfig.py → mcfg_entry.py} +4 -0
  53. machineconfig/scripts/python/msearch.py +21 -2
  54. machineconfig/scripts/python/nw/address.py +132 -0
  55. machineconfig/scripts/python/nw/devops_add_ssh_key.py +8 -5
  56. machineconfig/scripts/python/nw/ssh_debug_linux.py +7 -7
  57. machineconfig/scripts/python/nw/ssh_debug_windows.py +4 -4
  58. machineconfig/scripts/python/nw/wsl_windows_transfer.py +3 -2
  59. machineconfig/scripts/python/sessions.py +35 -20
  60. machineconfig/scripts/python/terminal.py +2 -2
  61. machineconfig/scripts/python/utils.py +12 -10
  62. machineconfig/scripts/windows/mounts/mount_ssh.ps1 +1 -1
  63. machineconfig/settings/lf/windows/lfcd.ps1 +1 -1
  64. machineconfig/settings/shells/nushell/config.nu +2 -2
  65. machineconfig/settings/shells/nushell/env.nu +45 -6
  66. machineconfig/settings/shells/nushell/init.nu +282 -95
  67. machineconfig/settings/shells/pwsh/init.ps1 +1 -0
  68. machineconfig/settings/shells/zsh/init.sh +0 -7
  69. machineconfig/setup_linux/web_shortcuts/interactive.sh +10 -10
  70. machineconfig/setup_windows/uv.ps1 +8 -1
  71. machineconfig/setup_windows/web_shortcuts/interactive.ps1 +10 -10
  72. machineconfig/setup_windows/web_shortcuts/quick_init.ps1 +3 -2
  73. machineconfig/utils/accessories.py +7 -4
  74. machineconfig/utils/code.py +6 -4
  75. machineconfig/utils/files/headers.py +2 -2
  76. machineconfig/utils/installer_utils/install_from_url.py +180 -0
  77. machineconfig/utils/installer_utils/installer_class.py +53 -47
  78. machineconfig/utils/installer_utils/{installer.py → installer_cli.py} +71 -65
  79. machineconfig/utils/{installer.py → installer_utils/installer_runner.py} +1 -25
  80. machineconfig/utils/links.py +2 -2
  81. machineconfig/utils/meta.py +30 -16
  82. machineconfig/utils/options.py +4 -4
  83. machineconfig/utils/path_extended.py +3 -3
  84. machineconfig/utils/path_helper.py +33 -31
  85. machineconfig/utils/schemas/layouts/layout_types.py +1 -1
  86. machineconfig/utils/ssh.py +143 -409
  87. machineconfig/utils/ssh_utils/abc.py +8 -0
  88. machineconfig/utils/ssh_utils/copy_from_here.py +110 -0
  89. machineconfig/utils/ssh_utils/copy_to_here.py +302 -0
  90. machineconfig/utils/ssh_utils/utils.py +141 -0
  91. machineconfig/utils/ssh_utils/wsl.py +168 -0
  92. machineconfig/utils/upgrade_packages.py +2 -1
  93. machineconfig/utils/ve.py +11 -4
  94. {machineconfig-7.57.dist-info → machineconfig-7.79.dist-info}/METADATA +1 -1
  95. {machineconfig-7.57.dist-info → machineconfig-7.79.dist-info}/RECORD +102 -92
  96. {machineconfig-7.57.dist-info → machineconfig-7.79.dist-info}/entry_points.txt +2 -2
  97. machineconfig/jobs/installer/linux_scripts/pgsql.sh +0 -41
  98. machineconfig/scripts/python/explore.py +0 -49
  99. /machineconfig/jobs/installer/linux_scripts/{warp-cli.sh → cloudflare_warp_cli.sh} +0 -0
  100. /machineconfig/{settings/shells/pwsh/profile.ps1 → scripts/python/helpers_fire_command/f.py} +0 -0
  101. /machineconfig/scripts/{Restore-ThunderbirdProfile.ps1 → windows/mounts/Restore-ThunderbirdProfile.ps1} +0 -0
  102. /machineconfig/utils/installer_utils/{installer_abc.py → installer_locator_utils.py} +0 -0
  103. {machineconfig-7.57.dist-info → machineconfig-7.79.dist-info}/WHEEL +0 -0
  104. {machineconfig-7.57.dist-info → machineconfig-7.79.dist-info}/top_level.txt +0 -0
@@ -0,0 +1,132 @@
1
+
2
+ from typing import cast, Optional
3
+
4
+
5
+ def get_all_ipv4_addresses() -> list[tuple[str, str]]:
6
+ import psutil
7
+ import socket
8
+ result: list[tuple[str, str]] = []
9
+ for iface, addrs in psutil.net_if_addrs().items():
10
+ for addr in addrs:
11
+ if addr.family == socket.AF_INET:
12
+ ip = addr.address
13
+ result.append((iface, ip))
14
+ return result
15
+
16
+
17
+ def select_lan_ipv4(prefer_vpn: bool) -> Optional[str]:
18
+ """
19
+ Choose the best 'real LAN' IPv4:
20
+ - Excludes loopback/link-local and (by default) VPN/tunnel/container ifaces
21
+ - Prefers physical-looking ifaces (eth/en*/wlan/wl*)
22
+ - Prefers RFC1918 LANs: 192.168/16 > 10/8 > 172.16/12
23
+ - Requires interface is UP
24
+ Set prefer_vpn=True to allow tunnel/VPN ifaces to compete.
25
+ """
26
+
27
+ import ipaddress
28
+ import re
29
+ from collections.abc import Sequence
30
+ import psutil
31
+
32
+ # Down-rank or exclude: tunnels/VPNs/bridges/containers (add your own if needed)
33
+ VIRTUAL_IFACE_PAT = re.compile(
34
+ r"^(?:lo|loopback|docker\d*|br-.*|veth.*|virbr.*|bridge.*|"
35
+ r"vboxnet.*|vmnet.*|zt.*|ham.*|tailscale.*|wg\d*|utun\d*|llw\d*|awdl\d*|"
36
+ r"tun\d*|tap\d*|cloudflarewarp.*|warp.*)$",
37
+ re.IGNORECASE,
38
+ )
39
+
40
+ # Light preference for names that look like real NICs
41
+ PHYSICAL_IFACE_PAT = re.compile(
42
+ r"^(?:eth\d*|en\d*|enp.*|ens.*|eno.*|wlan\d*|wl.*|.*wifi.*|.*ethernet.*)$",
43
+ re.IGNORECASE,
44
+ )
45
+
46
+ # Known noisy CIDRs to avoid
47
+ NOISY_NETS: list[ipaddress.IPv4Network] = [
48
+ ipaddress.IPv4Network("100.64.0.0/10"), # CGNAT (Tailscale/others)
49
+ ipaddress.IPv4Network("172.17.0.0/16"), # docker0 default
50
+ ipaddress.IPv4Network("172.18.0.0/16"),
51
+ ipaddress.IPv4Network("172.19.0.0/16"),
52
+ ipaddress.IPv4Network("192.168.49.0/24"), # minikube default
53
+ ipaddress.IPv4Network("10.0.2.0/24"), # VirtualBox NAT
54
+ ]
55
+
56
+ def _in_any(ip: ipaddress.IPv4Address, nets: Sequence[ipaddress.IPv4Network]) -> bool:
57
+ return any(ip in n for n in nets)
58
+
59
+ stats = psutil.net_if_stats()
60
+ best = None
61
+ best_score = -10**9
62
+ import socket
63
+ for iface, addrs in psutil.net_if_addrs().items():
64
+ st = stats.get(iface)
65
+ if not st or not st.isup:
66
+ continue
67
+
68
+ for a in addrs:
69
+ if a.family != socket.AF_INET or not a.address:
70
+ continue
71
+
72
+ ip_str = a.address
73
+ try:
74
+ ip = cast(ipaddress.IPv4Address, ipaddress.ip_address(ip_str))
75
+ except ValueError:
76
+ continue
77
+
78
+ # Exclude unusable classes
79
+ if ip.is_loopback or ip.is_link_local: # 127.0.0.0/8, 169.254.0.0/16
80
+ continue
81
+
82
+ # Hard filter: if it looks virtual and we don't prefer VPNs, skip it
83
+ if not prefer_vpn and VIRTUAL_IFACE_PAT.match(iface):
84
+ continue
85
+
86
+ # Hard filter: known noisy subnets (docker, cgnat, etc.)
87
+ if _in_any(ip, NOISY_NETS) and not prefer_vpn:
88
+ continue
89
+
90
+ # Base score
91
+ score = 0
92
+
93
+ # Prefer physical-looking names
94
+ if PHYSICAL_IFACE_PAT.match(iface):
95
+ score += 200
96
+
97
+ # Broadcast present usually means L2 LAN (not point-to-point)
98
+ # (psutil puts it on the same entry as .broadcast)
99
+ if getattr(a, "broadcast", None):
100
+ score += 100
101
+
102
+ # Prefer private RFC1918; rank families
103
+ if ip.is_private:
104
+ # Order: 192.168.x.x > 10.x.x.x > 172.16-31.x.x
105
+ ip_net = ipaddress.IPv4Network((ip, 32), strict=False)
106
+ if ipaddress.IPv4Network("192.168.0.0/16").supernet_of(ip_net):
107
+ score += 90
108
+ elif ipaddress.IPv4Network("10.0.0.0/8").supernet_of(ip_net):
109
+ score += 70
110
+ elif ipaddress.IPv4Network("172.16.0.0/12").supernet_of(ip_net):
111
+ score += 50
112
+ else:
113
+ # Public on a NIC is unusual for a home/office LAN
114
+ score -= 50
115
+
116
+ # Slight nudge by interface speed if known (>0 means psutil knows it)
117
+ # (Many tunnels report 0)
118
+ if getattr(st, "speed", 0) > 0:
119
+ score += 20
120
+
121
+ # Deterministic tie-breaker: prefer shorter iface name (eth0 over eth10)
122
+ score -= len(iface) * 0.01
123
+
124
+ if score > best_score:
125
+ best_score = score
126
+ best = ip_str
127
+
128
+ return best
129
+
130
+
131
+ if __name__ == "__main__":
132
+ print(select_lan_ipv4(False) or "No LAN IPv4 found")
@@ -137,11 +137,14 @@ def main(pub_path: Annotated[Optional[str], typer.Argument(..., help="Path to th
137
137
  console.print(Panel("🚀 SSH KEY AUTHORIZATION READY\nRun the generated script to apply changes", box=box.DOUBLE_EDGE, title_align="left"))
138
138
  from machineconfig.utils.code import run_shell_script
139
139
  run_shell_script(script=program)
140
- import socket
141
- s = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
142
- s.connect(('8.8.8.8', 80))
143
- local_ip_v4 = s.getsockname()[0]
144
- s.close()
140
+
141
+ import machineconfig.scripts.python.nw.address as helper
142
+ res = helper.select_lan_ipv4(prefer_vpn=False)
143
+ if res is None:
144
+ console.print(Panel("❌ ERROR: Could not determine local LAN IPv4 address", title="[bold red]Error[/bold red]", border_style="red"))
145
+ raise typer.Exit(code=1)
146
+ local_ip_v4 = res
147
+
145
148
  console.print(Panel(f"🌐 This computer is accessible at: {local_ip_v4}", title="[bold green]Network Info[/bold green]", border_style="green"))
146
149
  console.print(Panel("✅ SSH KEY AUTHORIZATION COMPLETED", box=box.DOUBLE_EDGE, title_align="left"))
147
150
 
@@ -1,7 +1,7 @@
1
1
 
2
2
 
3
3
  from platform import system
4
- from machineconfig.utils.path_extended import PathExtended
4
+ from pathlib import Path
5
5
  from rich.console import Console
6
6
  from rich.panel import Panel
7
7
  from rich import box
@@ -26,7 +26,7 @@ def ssh_debug_linux() -> dict[str, dict[str, str | bool]]:
26
26
  results: dict[str, dict[str, str | bool]] = {}
27
27
  issues_found: list[str] = []
28
28
 
29
- ssh_dir = PathExtended.home().joinpath(".ssh")
29
+ ssh_dir = Path.home().joinpath(".ssh")
30
30
  authorized_keys = ssh_dir.joinpath("authorized_keys")
31
31
 
32
32
  console.print(Panel("🔐 Checking SSH directory and authorized_keys...", title="[bold blue]File Permissions[/bold blue]", border_style="blue"))
@@ -106,7 +106,7 @@ def ssh_debug_linux() -> dict[str, dict[str, str | bool]]:
106
106
 
107
107
  console.print(Panel("🔌 Checking SSH port and listening status...", title="[bold blue]Network Status[/bold blue]", border_style="blue"))
108
108
 
109
- sshd_config_paths = [PathExtended("/etc/ssh/sshd_config"), PathExtended("/etc/sshd_config")]
109
+ sshd_config_paths = [Path("/etc/ssh/sshd_config"), Path("/etc/sshd_config")]
110
110
  sshd_config = None
111
111
  for config_path in sshd_config_paths:
112
112
  if config_path.exists():
@@ -236,7 +236,7 @@ def ssh_debug_linux() -> dict[str, dict[str, str | bool]]:
236
236
 
237
237
  console.print(Panel("🗂️ Checking for problematic files in /etc/...", title="[bold blue]System Files[/bold blue]", border_style="blue"))
238
238
 
239
- hosts_deny = PathExtended("/etc/hosts.deny")
239
+ hosts_deny = Path("/etc/hosts.deny")
240
240
  if hosts_deny.exists():
241
241
  hosts_deny_content = hosts_deny.read_text(encoding="utf-8")
242
242
  active_lines = [line.strip() for line in hosts_deny_content.splitlines() if line.strip() and not line.strip().startswith("#")]
@@ -252,14 +252,14 @@ def ssh_debug_linux() -> dict[str, dict[str, str | bool]]:
252
252
  results["hosts_deny"] = {"status": "ok", "message": "/etc/hosts.deny does not exist", "action": ""}
253
253
  console.print(Panel("✅ /etc/hosts.deny not present", title="[bold green]OK[/bold green]", border_style="green"))
254
254
 
255
- hosts_allow = PathExtended("/etc/hosts.allow")
255
+ hosts_allow = Path("/etc/hosts.allow")
256
256
  if hosts_allow.exists():
257
257
  results["hosts_allow"] = {"status": "ok", "message": "/etc/hosts.allow exists (check if needed)", "action": ""}
258
258
  console.print(Panel("ℹ️ /etc/hosts.allow exists\n💡 Ensure it allows SSH if using TCP wrappers", title="[bold blue]Info[/bold blue]", border_style="blue"))
259
259
 
260
260
  console.print(Panel("👤 Checking home directory permissions...", title="[bold blue]User Permissions[/bold blue]", border_style="blue"))
261
261
 
262
- home_dir = PathExtended.home()
262
+ home_dir = Path.home()
263
263
  home_stat = os.stat(home_dir)
264
264
  home_perms = oct(home_stat.st_mode)[-3:]
265
265
 
@@ -294,7 +294,7 @@ def ssh_debug_linux() -> dict[str, dict[str, str | bool]]:
294
294
 
295
295
  console.print(Panel("📋 Checking SSH logs for errors...", title="[bold blue]Logs[/bold blue]", border_style="blue"))
296
296
 
297
- log_files = [PathExtended("/var/log/auth.log"), PathExtended("/var/log/secure")]
297
+ log_files = [Path("/var/log/auth.log"), Path("/var/log/secure")]
298
298
  log_found = False
299
299
  for log_file in log_files:
300
300
  if log_file.exists():
@@ -1,7 +1,7 @@
1
1
 
2
2
 
3
3
  from platform import system
4
- from machineconfig.utils.path_extended import PathExtended
4
+ from pathlib import Path
5
5
  from rich.console import Console
6
6
  from rich.panel import Panel
7
7
  from rich import box
@@ -26,7 +26,7 @@ def ssh_debug_windows() -> dict[str, dict[str, str | bool]]:
26
26
  results: dict[str, dict[str, str | bool]] = {}
27
27
  issues_found: list[str] = []
28
28
 
29
- ssh_dir = PathExtended.home().joinpath(".ssh")
29
+ ssh_dir = Path.home().joinpath(".ssh")
30
30
  authorized_keys = ssh_dir.joinpath("authorized_keys")
31
31
 
32
32
  console.print(Panel("🔐 Checking SSH directory and authorized_keys...", title="[bold blue]File Permissions[/bold blue]", border_style="blue"))
@@ -124,7 +124,7 @@ def ssh_debug_windows() -> dict[str, dict[str, str | bool]]:
124
124
 
125
125
  console.print(Panel("🔌 Checking SSH port and listening status...", title="[bold blue]Network Status[/bold blue]", border_style="blue"))
126
126
 
127
- sshd_config_paths = [PathExtended("C:\\ProgramData\\ssh\\sshd_config"), PathExtended(os.environ.get("PROGRAMDATA", "C:\\ProgramData")).joinpath("ssh", "sshd_config")]
127
+ sshd_config_paths = [Path("C:\\ProgramData\\ssh\\sshd_config"), Path(os.environ.get("PROGRAMDATA", "C:\\ProgramData")).joinpath("ssh", "sshd_config")]
128
128
  sshd_config = None
129
129
  for config_path in sshd_config_paths:
130
130
  if config_path.exists():
@@ -168,7 +168,7 @@ def ssh_debug_windows() -> dict[str, dict[str, str | bool]]:
168
168
  if admin_authorized_keys_lines:
169
169
  console.print(Panel("⚠️ IMPORTANT: Administrators group uses different authorized_keys location\n💡 For admin users, keys should be in: C:\\ProgramData\\ssh\\administrators_authorized_keys\n💡 Not in user's .ssh/authorized_keys!", title="[bold yellow]Admin Users[/bold yellow]", border_style="yellow"))
170
170
 
171
- programdata_auth_keys = PathExtended(os.environ.get("PROGRAMDATA", "C:\\ProgramData")).joinpath("ssh", "administrators_authorized_keys")
171
+ programdata_auth_keys = Path(os.environ.get("PROGRAMDATA", "C:\\ProgramData")).joinpath("ssh", "administrators_authorized_keys")
172
172
  if programdata_auth_keys.exists():
173
173
  console.print(Panel("✅ administrators_authorized_keys file exists", title="[bold green]OK[/bold green]", border_style="green"))
174
174
  else:
@@ -35,15 +35,16 @@ def main(
35
35
  print("=" * 50 + "\n")
36
36
 
37
37
  path_obj = PathExtended(path).expanduser().absolute()
38
+ relative_home = PathExtended(path_obj.expanduser().absolute().relative_to(Path.home()))
38
39
 
39
40
  if same_file_system:
40
41
  print("⚠️ Using a not recommended transfer method! Copying files across the same file system.")
41
42
  if system == "Windows": # move files over to WSL
42
43
  print("📤 Transferring files from Windows to WSL...")
43
- path_obj.copy(folder=WSL_FROM_WIN.joinpath(UserName).joinpath(path_obj.rel2home().parent), overwrite=True) # the following works for files and folders alike.
44
+ path_obj.copy(folder=WSL_FROM_WIN.joinpath(UserName).joinpath(relative_home.parent), overwrite=True) # the following works for files and folders alike.
44
45
  else: # move files from WSL to win
45
46
  print("📤 Transferring files from WSL to Windows...")
46
- path_obj.copy(folder=WIN_FROM_WSL.joinpath(UserName).joinpath(path_obj.rel2home().parent), overwrite=True)
47
+ path_obj.copy(folder=WIN_FROM_WSL.joinpath(UserName).joinpath(relative_home.parent), overwrite=True)
47
48
  print("✅ Transfer completed successfully!\n")
48
49
  else:
49
50
  from machineconfig.utils.ssh import SSH
@@ -1,32 +1,47 @@
1
1
 
2
- from pathlib import Path
3
2
  from typing import Optional, Literal, Annotated
4
3
  import typer
5
4
 
6
- def balance_load(layout_path: Annotated[Path, typer.Argument(..., help="Path to the layout.json file")],
7
- max_thresh: Annotated[int, typer.Option(..., help="Maximum tabs per layout")],
8
- thresh_type: Annotated[Literal['number', 'weight'], typer.Option(..., help="Threshold type")],
9
- breaking_method: Annotated[Literal['moreLayouts', 'combineTabs'], typer.Option(..., help="Breaking method")],
10
- output_path: Annotated[Optional[Path], typer.Option(..., help="Path to write the adjusted layout.json file")] = None):
5
+ def balance_load(layout_path: Annotated[str, typer.Argument(..., help="Path to the layout.json file")],
6
+ max_thresh: Annotated[int, typer.Option(..., "--max-threshold", "-m", help="Maximum tabs per layout")],
7
+ thresh_type: Annotated[Literal['number', 'n', 'weight', 'w'], typer.Option(..., "--threshold-type", "-t", help="Threshold type")],
8
+ breaking_method: Annotated[Literal['moreLayouts', 'ml', 'combineTabs', 'ct'], typer.Option(..., "--breaking-method", "-b", help="Breaking method")],
9
+ output_path: Annotated[Optional[str], typer.Option(..., "--output-path", "-o", help="Path to write the adjusted layout.json file")] = None):
11
10
  """Adjust layout file to limit max tabs per layout, etc."""
11
+ thresh_type_resolved: dict[str, Literal['number', 'weight']] = {
12
+ 'number': 'number',
13
+ 'n': 'number',
14
+ 'weight': 'weight',
15
+ 'w': 'weight'
16
+ }
17
+ breaking_method_resolved: dict[str, Literal['moreLayouts', 'combineTabs']] = {
18
+ 'moreLayouts': 'moreLayouts',
19
+ 'ml': 'moreLayouts',
20
+ 'combineTabs': 'combineTabs',
21
+ 'ct': 'combineTabs'
22
+ }
23
+ from pathlib import Path
24
+ layout_path_obj = Path(layout_path).expanduser().absolute()
25
+
12
26
  from machineconfig.utils.schemas.layouts.layout_types import LayoutsFile
13
27
  import json
14
- layoutfile: LayoutsFile = json.loads(layout_path.read_text())
28
+ layoutfile: LayoutsFile = json.loads(layout_path_obj.read_text())
15
29
  layout_configs = layoutfile["layouts"]
16
30
  from machineconfig.cluster.sessions_managers.utils.load_balancer import limit_tab_num
17
- new_layouts = limit_tab_num(layout_configs=layout_configs, max_thresh=max_thresh, threshold_type=thresh_type, breaking_method=breaking_method)
31
+ new_layouts = limit_tab_num(layout_configs=layout_configs, max_thresh=max_thresh, threshold_type=thresh_type_resolved[thresh_type], breaking_method=breaking_method_resolved[breaking_method])
18
32
  layoutfile["layouts"] = new_layouts
19
- target_file = output_path if output_path is not None else layout_path.parent / f'{layout_path.stem}_adjusted_{max_thresh}_{thresh_type}_{breaking_method}.json'
33
+ target_file = Path(output_path) if output_path is not None else layout_path_obj.parent / f'{layout_path_obj.stem}_adjusted_{max_thresh}_{thresh_type}_{breaking_method}.json'
20
34
  target_file.parent.mkdir(parents=True, exist_ok=True)
21
35
  target_file.write_text(data=json.dumps(layoutfile, indent=4), encoding="utf-8")
22
36
  typer.echo(f"Adjusted layout saved to {target_file}")
23
37
 
24
38
 
25
- def select_layout(layouts_json_file: Path, selected_layouts_names: Optional[list[str]], select_interactively: bool) -> list["LayoutConfig"]:
39
+ def select_layout(layouts_json_file: str, selected_layouts_names: Optional[list[str]], select_interactively: bool) -> list["LayoutConfig"]:
26
40
  import json
27
41
  from machineconfig.utils.options import choose_from_options
28
42
  from machineconfig.utils.schemas.layouts.layout_types import LayoutsFile
29
- layout_file: LayoutsFile = json.loads(layouts_json_file.read_text(encoding="utf-8"))
43
+ from pathlib import Path
44
+ layout_file: LayoutsFile = json.loads(Path(layouts_json_file).read_text(encoding="utf-8"))
30
45
  if len(layout_file["layouts"]) == 0:
31
46
  raise ValueError(f"No layouts found in {layouts_json_file}")
32
47
  if selected_layouts_names is None: # choose all, or interactively
@@ -49,35 +64,35 @@ def select_layout(layouts_json_file: Path, selected_layouts_names: Optional[list
49
64
  return layouts_chosen
50
65
 
51
66
 
52
- def find_layout_file(layout_path: str, ) -> Path:
53
- from machineconfig.utils.path_extended import PathExtended
67
+ def find_layout_file(layout_path: str, ) -> str:
54
68
  from machineconfig.utils.path_helper import search_for_files_of_interest
55
69
  from machineconfig.utils.options import choose_from_options
56
70
  from machineconfig.utils.path_helper import match_file_name, sanitize_path
71
+ from pathlib import Path
57
72
  path_obj = sanitize_path(layout_path)
58
73
  if not path_obj.exists():
59
- choice_file = match_file_name(sub_string=layout_path, search_root=PathExtended.cwd(), suffixes={".json"})
74
+ choice_file = match_file_name(sub_string=layout_path, search_root=Path.cwd(), suffixes={".json"})
60
75
  elif path_obj.is_dir():
61
76
  print(f"🔍 Searching recursively for Python, PowerShell and Shell scripts in directory `{path_obj}`")
62
77
  files = search_for_files_of_interest(path_obj, suffixes={".py", ".sh", ".ps1"})
63
78
  print(f"🔍 Got #{len(files)} results.")
64
79
  choice_file = choose_from_options(multi=False, options=files, fzf=True, msg="Choose one option")
65
- choice_file = PathExtended(choice_file)
80
+ choice_file = Path(choice_file).expanduser().absolute()
66
81
  else:
67
82
  choice_file = path_obj
68
- return choice_file
83
+ return str(choice_file)
69
84
 
70
85
 
71
86
  def run(ctx: typer.Context,
72
87
  layout_path: Annotated[Optional[str], typer.Argument(..., help="Path to the layout.json file")] = None,
73
- max_tabs: Annotated[int, typer.Option(..., help="A Sanity checker that throws an error if any layout exceeds the maximum number of tabs to launch.")] = 10,
74
- max_layouts: Annotated[int, typer.Option(..., help="A Sanity checker that throws an error if the total number of *parallel layouts exceeds this number.")] = 10,
75
- sleep_inbetween: Annotated[float, typer.Option(..., help="Sleep time in seconds between launching layouts")] = 1.0,
88
+ max_tabs: Annotated[int, typer.Option(..., "--max-tabs", "-mt", help="A Sanity checker that throws an error if any layout exceeds the maximum number of tabs to launch.")] = 10,
89
+ max_layouts: Annotated[int, typer.Option(..., "--max-layouts", "-ml", help="A Sanity checker that throws an error if the total number of *parallel layouts exceeds this number.")] = 10,
90
+ sleep_inbetween: Annotated[float, typer.Option(..., "--sleep-inbetween", "-si", help="Sleep time in seconds between launching layouts")] = 1.0,
76
91
  monitor: Annotated[bool, typer.Option(..., "--monitor", "-m", help="Monitor the layout sessions for completion")] = False,
77
92
  parallel: Annotated[bool, typer.Option(..., "--parallel", "-p", help="Launch multiple layouts in parallel")] = False,
78
93
  kill_upon_completion: Annotated[bool, typer.Option(..., "--kill-upon-completion", "-k", help="Kill session(s) upon completion (only relevant if monitor flag is set)")] = False,
79
94
  choose: Annotated[Optional[str], typer.Option(..., "--choose", "-c", help="Comma separated names of layouts to be selected from the layout file passed")] = None,
80
- choose_interactively: Annotated[bool, typer.Option(..., "--choose-interactively", "-ia", help="Select layouts interactively")] = False
95
+ choose_interactively: Annotated[bool, typer.Option(..., "--choose-interactively", "-i", help="Select layouts interactively")] = False
81
96
  ):
82
97
  """
83
98
  Launch terminal sessions based on a layout configuration file.
@@ -1,5 +1,3 @@
1
- import subprocess
2
- # from machineconfig.utils.schemas.layouts.layout_types import LayoutConfig
3
1
  import typer
4
2
  from typing import Annotated
5
3
 
@@ -26,6 +24,7 @@ def choose_zellij_session(
26
24
  typer.Exit()
27
25
  return
28
26
  cmd = "zellij list-sessions"
27
+ import subprocess
29
28
  sessions: list[str] = subprocess.check_output(cmd, shell=True).decode().strip().split("\n")
30
29
  # filter out empty lines and keep raw lines (they contain creation info)
31
30
  sessions = [s for s in sessions if s.strip()]
@@ -63,6 +62,7 @@ def choose_zellij_session(
63
62
 
64
63
  def get_session_tabs() -> list[tuple[str, str]]:
65
64
  cmd = "zellij list-sessions"
65
+ import subprocess
66
66
  sessions: list[str] = subprocess.check_output(cmd, shell=True).decode().strip().split("\n")
67
67
  sessions = [strip_ansi_codes(s) for s in sessions]
68
68
  active_sessions = [s for s in sessions if "EXITED" not in s]
@@ -1,10 +1,12 @@
1
1
 
2
2
 
3
- from machineconfig.scripts.python.helpers_devops.cli_utils import download, merge_pdfs, compress_pdf
3
+ from machineconfig.scripts.python.helpers_devops.cli_utils import merge_pdfs, compress_pdf
4
4
  from machineconfig.scripts.python.helpers_utils.path import edit_file_with_hx, get_machine_specs, init_project, path
5
+ from machineconfig.scripts.python.helpers_utils.download import download
5
6
  import typer
6
7
  from typing import Annotated
7
8
 
9
+
8
10
  def kill_process(
9
11
  # name: Annotated[Optional[str], typer.Option(..., "--name", "-n", help="Name of the process to kill")],
10
12
  # command: Annotated[str, typer.Option(..., "--command", "-c", help="Match by command line instead of process name")] = "",
@@ -28,27 +30,27 @@ def upgrade_packages():
28
30
 
29
31
  def get_app() -> typer.Typer:
30
32
  app = typer.Typer(help="🛠️ utilities operations", no_args_is_help=True, add_help_option=False, add_completion=False)
31
- app.command(name="kill-process", no_args_is_help=False, help="[k] Choose a process to kill")(kill_process)
33
+ app.command(name="kill-process", no_args_is_help=False, help="⚔️ [k] Choose a process to kill")(kill_process)
32
34
  app.command(name="k", no_args_is_help=False, help="Choose a process to kill", hidden=True)(kill_process)
33
35
 
34
- app.command("path", no_args_is_help=False, help="📚 [p] NAVIGATE PATH variable with TUI")(path)
36
+ app.command("path", no_args_is_help=False, help="📚 [p] NAVIGATE PATH variable with TUI")(path)
35
37
  app.command("p", no_args_is_help=False, help="NAVIGATE PATH variable with TUI", hidden=True)(path)
36
38
 
37
- app.command(name="upgrade-packages", no_args_is_help=False, help="[up] Upgrade project dependencies.")(upgrade_packages)
39
+ app.command(name="upgrade-packages", no_args_is_help=False, help="⬆️ [up] Upgrade project dependencies.")(upgrade_packages)
38
40
  app.command(name="up", no_args_is_help=False, hidden=True)(upgrade_packages)
39
41
 
40
- app.command(name="download", no_args_is_help=True, help="[d] Download a file from a URL and optionally decompress it.")(download)
42
+ app.command(name="download", no_args_is_help=True, help="⬇️ [d] Download a file from a URL and optionally decompress it.")(download)
41
43
  app.command(name="d", no_args_is_help=True, hidden=True)(download)
42
- app.command(name="get-machine-specs", no_args_is_help=False, help="[g] Get machine specifications.")(get_machine_specs)
44
+ app.command(name="get-machine-specs", no_args_is_help=False, help="💻 [g] Get machine specifications.")(get_machine_specs)
43
45
  app.command(name="g", no_args_is_help=False, hidden=True)(get_machine_specs)
44
- app.command(name="init-project", no_args_is_help=False, help="[i] Initialize a project with a uv virtual environment and install dev packages.")(init_project)
46
+ app.command(name="init-project", no_args_is_help=False, help="🚀 [i] Initialize a project with a uv virtual environment and install dev packages.")(init_project)
45
47
  app.command(name="i", no_args_is_help=False, hidden=True)(init_project)
46
- app.command(name="edit", no_args_is_help=False, help="[e] Open a file in the default editor.")(edit_file_with_hx)
48
+ app.command(name="edit", no_args_is_help=False, help="✏️ [e] Open a file in the default editor.")(edit_file_with_hx)
47
49
  app.command(name="e", no_args_is_help=False, hidden=True)(edit_file_with_hx)
48
50
 
49
- app.command(name="pdf-merge", no_args_is_help=True, help="[pm] Merge two PDF files into one.")(merge_pdfs)
51
+ app.command(name="pdf-merge", no_args_is_help=True, help="📄 [pm] Merge two PDF files into one.")(merge_pdfs)
50
52
  app.command(name="pm", no_args_is_help=True, hidden=True)(merge_pdfs)
51
- app.command(name="pdf-compress", no_args_is_help=True, help="[pc] Compress a PDF file.")(compress_pdf)
53
+ app.command(name="pdf-compress", no_args_is_help=True, help="📦 [pc] Compress a PDF file.")(compress_pdf)
52
54
  app.command(name="pc", no_args_is_help=True, hidden=True)(compress_pdf)
53
55
 
54
56
  # app.command(name="copy", no_args_is_help=True, help="[c] Copy files or directories.")(copy)
@@ -7,7 +7,7 @@ $user = ''
7
7
  $sharePath = ''
8
8
  $driveLetter = ''
9
9
 
10
- uv run --python 3.14 --with "machineconfig>=7.57" python -m machineconfig.scripts.python.mount_ssh
10
+ uv run --python 3.14 --with "machineconfig>=7.79" python -m machineconfig.scripts.python.mount_ssh
11
11
 
12
12
  net use T: \\sshfs.kr\$user@$host.local
13
13
  # this worked: net use T: \\sshfs\alex@alex-p51s-5.local
@@ -17,7 +17,7 @@
17
17
 
18
18
  function lfcd {
19
19
  $tmp = [System.IO.Path]::GetTempFileName()
20
- ~\AppData\Local\Microsoft\WindowsApps\lf.exe -last-dir-path="$tmp" $args
20
+ & "$env:USERPROFILE\AppData\Local\Microsoft\WindowsApps\lf.exe" -last-dir-path="$tmp" $args
21
21
  if (Test-Path -PathType Leaf "$tmp")
22
22
  {
23
23
  $dir = Get-Content "$tmp"
@@ -1,3 +1,3 @@
1
+ # machineconfig Nushell configuration loader
1
2
 
2
-
3
- use C:\Users\aalsaf01\.config\machineconfig\settings\shells\nushell\init.nu
3
+ use "~/.config/machineconfig/settings/shells/nushell/init.nu"
@@ -1,13 +1,52 @@
1
+ # machineconfig Nushell environment setup
1
2
 
3
+ def reduce_non_empty [segments: list<string>] -> list<string> {
4
+ segments
5
+ | reduce --fold [] { |segment, acc|
6
+ if (($segment | str length) > 0) {
7
+ $acc | append $segment
8
+ } else {
9
+ $acc
10
+ }
11
+ }
12
+ }
2
13
 
3
- # as per https://github.com/starship/starship?tab=readme-ov-file#step-1-install-starship
4
- mkdir ~/.cache/starship
5
- starship init nu | save -f ~/.cache/starship/init.nu
14
+ let default_root = ($env.HOME | path join ".config" "machineconfig")
15
+ let config_root = (
16
+ $env.CONFIG_ROOT?
17
+ | default $default_root
18
+ | path expand
19
+ )
6
20
 
21
+ load-env { CONFIG_ROOT: $config_root }
7
22
 
23
+ let existing_segments = (
24
+ $env.PATH?
25
+ | default ""
26
+ | split row (char esep)
27
+ | reduce_non_empty
28
+ )
8
29
 
9
- # echo $nu.env-path
10
- # as per https://github.com/ajeetdsouza/zoxide?tab=readme-ov-file#installation
11
- zoxide init nushell | save -f ~/.zoxide.nu
30
+ let desired_paths = [
31
+ ($config_root | path join "scripts")
32
+ ($env.HOME | path join "dotfiles" "scripts" "linux")
33
+ ($env.HOME | path join ".local" "bin")
34
+ ($env.HOME | path join ".cargo" "bin")
35
+ "/usr/games"
36
+ ]
37
+
38
+ let merged_segments = (
39
+ $desired_paths
40
+ | reduce --fold $existing_segments { |entry, acc|
41
+ if (($entry | path exists) and (not ($entry in $acc))) {
42
+ $acc | append $entry
43
+ } else {
44
+ $acc
45
+ }
46
+ }
47
+ )
48
+
49
+ let new_path = ($merged_segments | str join (char esep))
50
+ load-env { PATH: $new_path }
12
51
 
13
52