Created
September 17, 2026 03:17
-
-
Save jpolvora/d1e6e30f30c75548bc66cf730b6f6b61 to your computer and use it in GitHub Desktop.
muse-code wrappers: run the native Muse Code Windows build (installed via irm https://dev.meta.ai/install.ps1 | iex) from Git Bash MINGW (with MSYS path translation) and from cmd/pwsh
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #!/usr/bin/env bash | |
| # muse-code — Git Bash (MINGW/MSYS/CYGWIN) wrapper for the native Muse Code Windows build. | |
| # | |
| # Background: the installer (irm https://dev.meta.ai/install.ps1 | iex) puts the | |
| # real Windows build in %LOCALAPPDATA%\Programs\muse (muse.cmd + muse-bin-*.exe), | |
| # which is NOT on PATH. The bash launcher at ~/.local/bin/muse only supports | |
| # macOS/Linux and dies with "unsupported platform: MINGW64_..." under Git Bash. | |
| # This wrapper (named muse-code to avoid clashing with `muse`) forwards to the | |
| # Windows .exe with MSYS path translation, so `muse-code` works from Git Bash. | |
| # | |
| # Usage: muse-code [--version] [--help] [PROMPT] ... | |
| # Env: MUSE_HOME override install dir (unix- or windows-style path) | |
| # MUSE_CODE_DEBUG=1 print resolved binary to stderr | |
| set -euo pipefail | |
| resolve_muse_dir() { | |
| local dir candidate | |
| if [[ -n "${MUSE_HOME:-}" ]]; then | |
| # Accept windows-style override too (C:\... or C:/...). | |
| if [[ "${MUSE_HOME}" =~ ^[A-Za-z]: ]]; then | |
| candidate="$(cygpath -u "$MUSE_HOME" 2>/dev/null || printf '%s' "$MUSE_HOME")" | |
| printf '%s\n' "$candidate" | |
| else | |
| printf '%s\n' "$MUSE_HOME" | |
| fi | |
| return 0 | |
| fi | |
| if [[ -n "${LOCALAPPDATA:-}" ]]; then | |
| if candidate="$(cygpath -u "$LOCALAPPDATA" 2>/dev/null)"; then | |
| printf '%s/Programs/muse\n' "$candidate" | |
| return 0 | |
| fi | |
| fi | |
| dir="${HOME:-/c/Users/jpolv}" | |
| printf '%s/AppData/Local/Programs/muse\n' "$dir" | |
| } | |
| resolve_binary() { | |
| local dir="$1" ver_file ver bin latest | |
| ver_file="$dir/.muse-version" | |
| if [[ -r "$ver_file" ]]; then | |
| ver="$(tr -d '\r\n\t ' <"$ver_file" 2>/dev/null || true)" | |
| if [[ -n "$ver" ]]; then | |
| bin="$dir/muse-bin-$ver.exe" | |
| if [[ -x "$bin" ]]; then | |
| printf '%s\n' "$bin" | |
| return 0 | |
| fi | |
| fi | |
| fi | |
| # Fallback: newest muse-bin-*.exe (glob sorts lexically; normally only one). | |
| latest="" | |
| shopt -s nullglob | |
| for bin in "$dir"/muse-bin-*.exe; do | |
| if [[ -f "$bin" ]]; then | |
| latest="$bin" | |
| fi | |
| done | |
| shopt -u nullglob | |
| if [[ -n "$latest" ]]; then | |
| printf '%s\n' "$latest" | |
| return 0 | |
| fi | |
| return 1 | |
| } | |
| # Convert one argv element to a Windows path when it is path-like. | |
| # Leaves flags, prompts, and option values that are not paths untouched. | |
| maybe_win_path() { | |
| local a="$1" base suffix w | |
| if [[ -z "$a" ]]; then printf '\n'; return 0; fi | |
| if [[ "$a" == -* ]]; then printf '%s\n' "$a"; return 0; fi | |
| if [[ "$a" == *$'\n'* ]]; then printf '%s\n' "$a"; return 0; fi | |
| # Existing file/dir (works for relative, unix-absolute, and windows-style). | |
| if [[ -e "$a" ]]; then | |
| cygpath -w "$a" | |
| return 0 | |
| fi | |
| # file:line or file:line:col where the file part exists. | |
| if [[ "$a" =~ ^([^:]+):[0-9]+(:[0-9]+)?$ ]]; then | |
| base="${BASH_REMATCH[1]}" | |
| suffix="${a:${#base}}" | |
| if [[ -e "$base" ]]; then | |
| w="$(cygpath -w "$base")" | |
| printf '%s%s\n' "$w" "$suffix" | |
| return 0 | |
| fi | |
| fi | |
| # Absolute MSYS path for a not-yet-existing file (e.g. output path). | |
| # Only single-token values (no spaces) to avoid mangling prompt sentences. | |
| if [[ "$a" == /* || "$a" == ~* ]]; then | |
| if [[ "$a" != *' '* && "$a" != *$'\t'* ]]; then | |
| if w="$(cygpath -w "$a" 2>/dev/null)"; then | |
| printf '%s\n' "$w" | |
| return 0 | |
| fi | |
| fi | |
| fi | |
| printf '%s\n' "$a" | |
| } | |
| main() { | |
| local muse_dir binary | |
| muse_dir="$(resolve_muse_dir)" | |
| if ! binary="$(resolve_binary "$muse_dir")"; then | |
| printf 'muse-code: Windows binary not found under %s\n' "$muse_dir" >&2 | |
| printf 'muse-code: reinstall with: powershell -c "irm https://dev.meta.ai/install.ps1 | iex"\n' >&2 | |
| printf 'muse-code: or point MUSE_HOME at your install dir.\n' >&2 | |
| exit 1 | |
| fi | |
| if [[ "${MUSE_CODE_DEBUG:-0}" == 1 ]]; then | |
| printf 'muse-code: dir=%s\nmuse-code: bin=%s\n' "$muse_dir" "$binary" >&2 | |
| fi | |
| local out=() arg name val w | |
| for arg in "$@"; do | |
| # --opt=value form: translate only the value part when path-like. | |
| if [[ "$arg" == --*=* ]]; then | |
| name="${arg%%=*}" | |
| val="${arg#*=}" | |
| w="$(maybe_win_path "$val")" | |
| out+=("$name=$w") | |
| else | |
| w="$(maybe_win_path "$arg")" | |
| out+=("$w") | |
| fi | |
| done | |
| # Stop MSYS from doing its own implicit conversion (we already converted). | |
| export MSYS2_ARG_CONV_EXCL="*" | |
| exec "$binary" "${out[@]+"${out[@]}"}" | |
| } | |
| main "$@" |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| @echo off | |
| rem muse-code.cmd — cmd/pwsh wrapper for the native Muse Code Windows build. | |
| rem Includes the absolute install path so it works without PATH changes. | |
| rem Installed via: irm https://dev.meta.ai/install.ps1 ^| iex | |
| setlocal | |
| if defined MUSE_HOME ( | |
| set "MUSE_CMD=%MUSE_HOME%\muse.cmd" | |
| ) else if defined LOCALAPPDATA ( | |
| set "MUSE_CMD=%LOCALAPPDATA%\Programs\muse\muse.cmd" | |
| ) else ( | |
| set "MUSE_CMD=%USERPROFILE%\AppData\Local\Programs\muse\muse.cmd" | |
| ) | |
| if not exist "%MUSE_CMD%" ( | |
| echo muse-code: not found: "%MUSE_CMD%" 1>&2 | |
| echo muse-code: reinstall with: powershell -c "irm https://dev.meta.ai/install.ps1 ^| iex" 1>&2 | |
| exit /b 1 | |
| ) | |
| "%MUSE_CMD%" %* | |
| exit /b %ERRORLEVEL% |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment