Skip to content

feat: configurable macOS terminal app via EditorPrefs#1117

Open
skyhills13 wants to merge 2 commits into
CoplayDev:betafrom
skyhills13:feat/macos-terminal-app-pref
Open

feat: configurable macOS terminal app via EditorPrefs#1117
skyhills13 wants to merge 2 commits into
CoplayDev:betafrom
skyhills13:feat/macos-terminal-app-pref

Conversation

@skyhills13
Copy link
Copy Markdown

@skyhills13 skyhills13 commented May 10, 2026

Summary

  • The macOS branch of TerminalLauncher.CreateTerminalProcessStartInfo hardcodes open -a Terminal, so Terminal.app spawns even when the user runs iTerm2 / Warp / Alacritty / etc. macOS LaunchServices resolves -a Terminal by app name, so iTerm's Make iTerm2 default term setting cannot redirect it — the package code itself has to expose the choice.
  • Read the terminal app name from a new EditorPref (MCPForUnity.MacOSTerminalApp). Unset/empty/whitespace → falls back to "Terminal", so existing users see no change.
  • Quote the app name in the -a argument so values with spaces (e.g. iTerm 2) work.
  • Register the key in EditorPrefsWindow's knownPrefTypes (String) so it shows up in the existing EditorPrefs UI — no new window/menu surface needed.

Motivation (concrete case)

In my own project I had to embed this package and hand-edit the line to -a iTerm to stop Terminal.app from popping up on every server restart. That hand-edit is what this PR generalizes: same root change, but driven by EditorPrefs so it survives package upgrades and works for any macOS terminal app the user prefers.

How to use

  1. Window → MCP for Unity → EditorPrefs (or whichever entry shows the EditorPrefs window).
  2. Set MCPForUnity.MacOSTerminalApp to the bundle name you want, e.g. iTerm, Warp, Alacritty. Same value you would pass to open -a <name>.
  3. Restart the MCP server. The new terminal window opens in the chosen app.

Compatibility

  • Default behavior (key unset, empty, or whitespace-only) → Terminal. Identical to current behavior.
  • macOS only. Windows and Linux branches unchanged.

Test plan (not yet executed in this PR — happy to do whatever the maintainers want before merge)

  • macOS: set MCPForUnity.MacOSTerminalApp = "iTerm", restart server → iTerm window opens with the MCP server log.
  • macOS: clear the EditorPref → Terminal.app opens (regression check).
  • macOS: name with a space (e.g. iTerm 2) — quoting handles it.
  • Editor build check on Windows / Linux (no behavioral change there; just confirm using UnityEditor; is fine — it already is in this codebase, so this is a formality).

The only verification I have done so far is the equivalent hand-patched line (-a iTerm hardcoded) running in my own project against the current beta package, which confirms open -a <app> is the right control point. The EditorPrefs-driven path in this PR has not yet been exercised in a live Unity build.

Notes for reviewers

  • I deliberately avoided adding a new dedicated settings UI — the existing EditorPrefs window already lists registered keys, so adding the key to knownPrefTypes is enough surface for now. Happy to wire a dropdown into the main MCP window if you'd prefer something more discoverable.
  • No tests added. The macOS branch is #if UNITY_EDITOR_OSX and the new logic is EditorPrefs.GetString + a fallback string check, which is hard to unit-test without abstracting EditorPrefs. If a small helper extraction is preferred for testability, let me know and I'll add it.

🤖 Generated with Claude Code

Summary by CodeRabbit

  • New Features
    • macOS users can configure their preferred terminal app via a new editor preference. If unset, the editor defaults to the standard Terminal app for compatibility.
  • Tests
    • Added macOS-focused tests validating terminal selection fallback, trimming behavior, and correct quoting of app names and script paths containing spaces.

The macOS branch of TerminalLauncher.CreateTerminalProcessStartInfo
hardcoded `open -a Terminal`, which forces Terminal.app to spawn even
when the user prefers another terminal (iTerm2, Warp, etc.). macOS
LaunchServices resolves `-a Terminal` by name, so iTerm's
"Make iTerm2 default term" setting cannot redirect it.

Read the terminal app name from the new `MCPForUnity.MacOSTerminalApp`
EditorPref. Empty/unset falls back to "Terminal" so existing behavior
is preserved for users who never touch the setting.

The key is registered in EditorPrefsWindow's `knownPrefTypes` so it
shows up in the EditorPrefs window as a String entry.

Argument is now quoted (`-a "{app}"`) to handle names with spaces such
as "iTerm 2".

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai Bot commented May 10, 2026

Review Change Stack

📝 Walkthrough

Walkthrough

This PR adds user configuration for the macOS terminal application used in terminal launching. A new EditorPrefs key is introduced, integrated into the terminal launcher logic with a sensible default, registered in the EditorPrefs UI settings window, and covered by unit tests.

Changes

macOS Terminal App Configuration

Layer / File(s) Summary
EditorPrefs Key Definition
MCPForUnity/Editor/Constants/EditorPrefKeys.cs
New internal constant MacOSTerminalApp = "MCPForUnity.MacOSTerminalApp" added to centralized EditorPrefs keys.
Terminal Launcher Implementation
MCPForUnity/Editor/Services/Server/TerminalLauncher.cs, TestProjects/UnityMCPTests/Assets/Tests/EditMode/Services/Server/TerminalLauncherTests.cs
Adds editor imports and two helpers: ResolveMacTerminalApp (fallback/trim) and BuildMacOpenArguments (quoted -a "<App>" "<ScriptPath>"), replaces hardcoded "Terminal" usage with the EditorPrefs-configured value, and adds tests validating resolution and argument quoting.
EditorPrefs UI Registration
MCPForUnity/Editor/Windows/EditorPrefs/EditorPrefsWindow.cs
Registers MacOSTerminalApp in knownPrefTypes mapping as a String type for UI display.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~8 minutes

Possibly related PRs

  • CoplayDev/unity-mcp#491: Changes to the EditorPrefsWindow and EditorPrefKeys system; related to preference registration and UI handling.

Poem

🐰 I hopped through prefs to make it right,
A macOS terminal now set by sight,
Trimmed and quoted, ready to run,
From "Terminal" to a name you’ve fun,
This rabbit cheers — launch times are bright!

🚥 Pre-merge checks | ✅ 3 | ❌ 2

❌ Failed checks (1 warning, 1 inconclusive)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 30.77% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
Description check ❓ Inconclusive PR description provided is comprehensive and well-structured, covering motivation, implementation details, usage instructions, and test plan, but does not follow the repository's standardized template format. Reformat the PR description to match the template structure with sections for Type of Change, Changes Made, Compatibility/Package Source, Testing/Screenshots, Documentation Updates, and Related Issues to ensure consistency with repository standards.
✅ Passed checks (3 passed)
Check name Status Explanation
Title check ✅ Passed The title 'feat: configurable macOS terminal app via EditorPrefs' accurately summarizes the main change: enabling user-configurable macOS terminal app selection via EditorPrefs instead of hardcoding Terminal.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR makes the macOS terminal app used to launch the MCP server configurable via Unity EditorPrefs, avoiding a hardcoded dependency on Terminal.app while keeping the existing default behavior when unset.

Changes:

  • Added a new EditorPrefs key (MCPForUnity.MacOSTerminalApp) to choose which macOS terminal app open -a targets (fallback remains "Terminal").
  • Updated TerminalLauncher to read and use the configured terminal app name (including quoting for names with spaces).
  • Registered the new key in EditorPrefsWindow so it appears in the existing EditorPrefs UI.

Reviewed changes

Copilot reviewed 3 out of 3 changed files in this pull request and generated 2 comments.

File Description
MCPForUnity/Editor/Windows/EditorPrefs/EditorPrefsWindow.cs Registers the new macOS terminal app EditorPref key as a known string pref.
MCPForUnity/Editor/Services/Server/TerminalLauncher.cs Reads the preferred macOS terminal app from EditorPrefs and uses it in the open -a invocation.
MCPForUnity/Editor/Constants/EditorPrefKeys.cs Adds the MCPForUnity.MacOSTerminalApp EditorPref key constant.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment on lines +50 to +55
string terminalApp = EditorPrefs.GetString(EditorPrefKeys.MacOSTerminalApp, "Terminal");
if (string.IsNullOrWhiteSpace(terminalApp)) terminalApp = "Terminal";
return new System.Diagnostics.ProcessStartInfo
{
FileName = "/usr/bin/open",
Arguments = $"-a Terminal \"{scriptPath}\"",
Arguments = $"-a \"{terminalApp}\" \"{scriptPath}\"",
Comment on lines +50 to +55
string terminalApp = EditorPrefs.GetString(EditorPrefKeys.MacOSTerminalApp, "Terminal");
if (string.IsNullOrWhiteSpace(terminalApp)) terminalApp = "Terminal";
return new System.Diagnostics.ProcessStartInfo
{
FileName = "/usr/bin/open",
Arguments = $"-a Terminal \"{scriptPath}\"",
Arguments = $"-a \"{terminalApp}\" \"{scriptPath}\"",
@Scriptwonder
Copy link
Copy Markdown
Collaborator

Hi thanks for the PR! Late to leave this review but do you think you can fulfill your test plan? Just want to double check before merging this.

Extract the macOS terminal-app fallback and `open -a` argument building
into pure internal helpers (ResolveMacTerminalApp, BuildMacOpenArguments)
so the EditorPrefs-driven behavior is unit-testable without a live Editor.

Adds EditMode tests covering the test plan logic: unset/empty/whitespace
falls back to Terminal, custom apps are used, and quoting handles app names
and script paths containing spaces (e.g. "iTerm 2").

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
@dobi222
Copy link
Copy Markdown

dobi222 commented Jun 8, 2026

Thanks for the nudge! I've addressed the testability gap from my original notes.

Rather than leaving the macOS logic untestable behind #if UNITY_EDITOR_OSX, I extracted the two pure pieces of behavior into internal static helpers on TerminalLauncher:

  • ResolveMacTerminalApp(configuredApp) — the EditorPrefs fallback (unset/empty/whitespace → Terminal, otherwise trimmed value)
  • BuildMacOpenArguments(configuredApp, scriptPath) — the open -a "<app>" "<script>" argument string

The #if UNITY_EDITOR_OSX branch now reads the EditorPref and routes through these, so behavior is unchanged but the decision logic is unit-testable without a live Editor or EditorPrefs.

Added EditMode tests in TerminalLauncherTests covering the test-plan cases:

  • unset / empty / whitespace-only → falls back to Terminal (regression check)
  • custom app names (iTerm, Warp) are used
  • quoting handles app names and script paths containing spaces (e.g. iTerm 2, /Users/me/My Project/...)

These are platform-agnostic pure functions, so the tests run on the Linux CI runner too — no macOS-only gating needed. The one thing automated tests can't assert is "an iTerm window visually appears," but that's purely open -a's job; the only thing this PR changes is the argument string, which is now fully covered.

Could you re-apply safe-to-test so the Unity Tests workflow runs against the new commit? (Pushed as edfb2da.)

  • I didn't have a window machine so I cannot check last test plan

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.

4 participants