fd
This commit is contained in:
@@ -551,18 +551,18 @@ def main() -> int:
|
||||
|
||||
if system == "windows":
|
||||
user_bin = Path(os.environ.get("USERPROFILE", str(home))) / "bin"
|
||||
mm_ps1 = user_bin / "mm.ps1"
|
||||
mm_bat = user_bin / "mm.bat"
|
||||
|
||||
print(f"Checking for shim files:")
|
||||
print(f" mm.ps1: {'✓' if mm_ps1.exists() else '✗'} ({mm_ps1})")
|
||||
print(f" mm.bat: {'✓' if mm_bat.exists() else '✗'} ({mm_bat})")
|
||||
print()
|
||||
|
||||
if mm_ps1.exists():
|
||||
ps1_content = mm_ps1.read_text(encoding="utf-8")
|
||||
if "$repo =" in ps1_content or "$py =" in ps1_content:
|
||||
print(f" mm.ps1 content looks valid ({len(ps1_content)} bytes)")
|
||||
if mm_bat.exists():
|
||||
bat_content = mm_bat.read_text(encoding="utf-8")
|
||||
if "REPO=" in bat_content or "ENTRY=" in bat_content:
|
||||
print(f" mm.bat content looks valid ({len(bat_content)} bytes)")
|
||||
else:
|
||||
print(f" ⚠️ mm.ps1 content may be corrupted")
|
||||
print(f" ⚠️ mm.bat content may be corrupted")
|
||||
print()
|
||||
|
||||
# Check PATH
|
||||
@@ -992,34 +992,35 @@ if (Test-Path (Join-Path $repo 'CLI.py')) {
|
||||
if not (repo / "scripts").exists():
|
||||
print(f"WARNING: scripts folder not found at {repo}/scripts - mm command may not work", file=sys.stderr)
|
||||
|
||||
# Write mm.ps1 (PowerShell shim for global command)
|
||||
mm_ps1 = user_bin / "mm.ps1"
|
||||
repo_ps1_str = str(repo).replace("\\", "\\\\")
|
||||
ps1_text = (
|
||||
"$repo = '{repo}'\n"
|
||||
"$venv = Join-Path $repo '.venv'\n"
|
||||
"$py = Join-Path $venv 'Scripts' 'python.exe'\n"
|
||||
"$entry = Join-Path $repo 'scripts' 'cli_entry.py'\n"
|
||||
"if (Test-Path $py) {{\n"
|
||||
" & $py $entry $args\n"
|
||||
" exit $LASTEXITCODE\n"
|
||||
"}}\n"
|
||||
"Write-Host 'MM: venv python not found at '$py\n"
|
||||
"python $entry $args\n"
|
||||
"exit $LASTEXITCODE\n"
|
||||
).format(repo=repo_ps1_str)
|
||||
if mm_ps1.exists():
|
||||
bak = mm_ps1.with_suffix(f".bak{int(time.time())}")
|
||||
mm_ps1.replace(bak)
|
||||
mm_ps1.write_text(ps1_text, encoding="utf-8")
|
||||
# Write mm.bat (batch shim works in all shells, bypasses PowerShell execution policy)
|
||||
mm_bat = user_bin / "mm.bat"
|
||||
repo_bat_str = str(repo)
|
||||
bat_text = (
|
||||
"@echo off\n"
|
||||
"setlocal enabledelayedexpansion\n"
|
||||
f'set "REPO={repo_bat_str}"\n'
|
||||
"set \"VENV=!REPO!\\.venv\"\n"
|
||||
"set \"PY=!VENV!\\Scripts\\python.exe\"\n"
|
||||
"set \"ENTRY=!REPO!\\scripts\\cli_entry.py\"\n"
|
||||
"if exist \"!PY!\" (\n"
|
||||
" \"!PY!\" \"!ENTRY!\" %*\n"
|
||||
" exit /b !ERRORLEVEL!\n"
|
||||
")\n"
|
||||
"python \"!ENTRY!\" %*\n"
|
||||
"exit /b !ERRORLEVEL!\n"
|
||||
)
|
||||
if mm_bat.exists():
|
||||
bak = mm_bat.with_suffix(f".bak{int(time.time())}")
|
||||
mm_bat.replace(bak)
|
||||
mm_bat.write_text(bat_text, encoding="utf-8")
|
||||
|
||||
# Validate that the PowerShell shim was created correctly
|
||||
ps1_ok = mm_ps1.exists() and len(mm_ps1.read_text(encoding="utf-8")) > 0
|
||||
if not ps1_ok:
|
||||
raise RuntimeError("Failed to create mm.ps1 shim")
|
||||
# Validate that the batch shim was created correctly
|
||||
bat_ok = mm_bat.exists() and len(mm_bat.read_text(encoding="utf-8")) > 0
|
||||
if not bat_ok:
|
||||
raise RuntimeError("Failed to create mm.bat shim")
|
||||
|
||||
if args.debug:
|
||||
print(f"DEBUG: Created mm.ps1 ({len(ps1_text)} bytes)")
|
||||
print(f"DEBUG: Created mm.bat ({len(bat_text)} bytes)")
|
||||
print(f"DEBUG: Repo path embedded in shim: {repo}")
|
||||
print(f"DEBUG: Venv location: {repo}/.venv")
|
||||
print(f"DEBUG: Shim directory: {user_bin}")
|
||||
|
||||
Reference in New Issue
Block a user