Skip to content

fix: cross-platform Node wrapper for ssh-manager CLI (#22)#23

Open
bvisible wants to merge 1 commit intomainfrom
fix/windows-cli-wrapper
Open

fix: cross-platform Node wrapper for ssh-manager CLI (#22)#23
bvisible wants to merge 1 commit intomainfrom
fix/windows-cli-wrapper

Conversation

@bvisible
Copy link
Copy Markdown
Owner

@bvisible bvisible commented Apr 9, 2026

Summary

Fixes #22 — on native Windows shells (PowerShell, cmd) the ssh-manager CLI failed immediately after a global install because npm cannot wrap a Bash-shebang script properly: the generated .ps1/.cmd shim tried to run /bin/bash.exe, and even when a bash was on PATH, Windows paths (C:\...) were not translated into POSIX form so the script could not be located.

This PR replaces the ssh-manager bin entry with a small cross-platform Node wrapper that delegates to the existing Bash CLI. No Bash code was touched — the 2500-line CLI keeps running unchanged on Unix.

What the wrapper does

  • On Unix — forwards argv to cli/ssh-manager via bash (zero behavior change).
  • On Windows, probes in order:
    1. Git Bash — looks in %ProgramFiles%\Git\bin\bash.exe, %ProgramFiles(x86)%, %LOCALAPPDATA%\Programs\Git\bin\bash.exe, and two hard-coded defaults. Paths are converted to MSYS form (C:\foo/c/foo) before invocation.
    2. WSL — detected via wsl.exe --status; script path is converted to /mnt/c/... and launched via wsl.exe bash ....
    3. bash on PATH — last resort (custom MSYS2 installs, etc.).
  • If none of the three are available, prints an actionable message with links to Git for Windows and instructions for wsl --install, and exits 1.

The MCP server itself (mcp-ssh-managersrc/index.js) is untouched and continues to work on Windows with zero dependencies on Bash.

Files changed

  • cli/ssh-manager.js (new) — Node wrapper, ESM, no external deps.
  • package.jsonbin.ssh-manager now points at cli/ssh-manager.js instead of cli/ssh-manager.

How to test

Unix (should behave exactly as before)

npm install
node cli/ssh-manager.js --version
node cli/ssh-manager.js --help
node cli/ssh-manager.js server list

Windows (PowerShell / cmd)

# From a local clone
npm install -g .

# Then in a fresh shell
ssh-manager --version
ssh-manager --help
ssh-manager server add

Expected:

  • With Git for Windows installed → commands run transparently via Git Bash.
  • With WSL installed (and no Git Bash) → commands run via wsl.exe bash.
  • With neither → a clear error message explaining how to install Git for Windows or WSL.

Test plan

  • node --check cli/ssh-manager.js passes
  • ./scripts/validate.sh passes
  • node cli/ssh-manager.js --version on macOS forwards correctly to the Bash script
  • node cli/ssh-manager.js --help on macOS forwards correctly (colors, subcommand list preserved)
  • Manual verification on Windows 11 + Git for Windows
  • Manual verification on Windows 11 + WSL only
  • Manual verification on Windows 11 with neither (expect actionable error)

The last three items require a Windows machine — @Eleef opened the original issue and offered to help test, so I'd like to ask them to confirm on their setup before we merge.

Closes #22

The ssh-manager bin entry used to point directly at a Bash script, which
npm cannot wrap on native Windows shells — the generated .ps1/.cmd shim
tries to invoke /bin/bash.exe, and even when a bash is available, Windows
paths are not translated into POSIX form so the script cannot be found.

Replace the bin entry with a small Node wrapper that:

- On Unix, simply forwards argv to the existing Bash script via `bash`.
- On Windows, probes for Git Bash (Program Files / LocalAppData), then
  WSL, then `bash` on PATH. Windows paths are converted to MSYS
  (/c/...) or WSL (/mnt/c/...) form as appropriate before invocation.
- Prints an actionable message pointing at Git for Windows or WSL when
  no compatible Bash interpreter can be located.

The underlying Bash CLI is untouched, so there is no regression for
existing Unix users. Closes #22.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Windows global install: ssh-manager fails due /bin/bash shim/path handling

1 participant