Repository navigation
Offer opening iTerm2 as a tab instead of a new window (issue #712) - #713
Merged
Merged
Conversation
goneng
force-pushed
the
open-in-terminal-as-tab
branch
from
September 21, 2026 23:20
2d7c234 to
5b318bb
Compare
goneng
force-pushed
the
open-in-terminal-as-tab
branch
2 times, most recently
from
September 22, 2026 05:33
fa18760 to
f8a6b75
Compare
goneng
force-pushed
the
open-in-terminal-as-tab
branch
2 times, most recently
from
September 22, 2026 10:50
885c6b1 to
7ce0673
Compare
Reuse a terminal window that is already open, which is usually what is wanted when a repository is sent to iTerm2. - Add an "Open as tab" preference beside the terminal handler, off by default so the existing behaviour is unchanged - Write the command into a new tab of iTerm2's current window when the preference is on, falling back to a new window when iTerm2 has none open - Take the window iTerm2 opens for itself when GitX is what launched it, rather than asking for a second one on top; sending the create-window event to a handler that is not running launched it, let it open its own window, and then added another, leaving two sessions in both modes - Gray the preference out for Terminal.app, which has no Apple Event for opening a tab - Clear the opened session with `tput clear` rather than `clear`, which emits ESC[3J and makes iTerm2 break into the new tab to ask whether discarding the scrollback is allowed - Raise the checkbox to sit directly under the terminal popup, so it reads as belonging to "Open in Terminal:" rather than to the Gist options below it
goneng
force-pushed
the
open-in-terminal-as-tab
branch
from
September 22, 2026 11:54
7ce0673 to
6f3b10f
Compare
goneng
marked this pull request as ready for review
September 22, 2026 12:19
hannesa2
approved these changes
Sep 22, 2026
hannesa2
left a comment
Contributor
There was a problem hiding this comment.
It's fine for me. Let’s wait for the review by Copilot, in case it finds anything important.
Contributor
There was a problem hiding this comment.
Copilot review overview
🟢 Approval recommended
No unresolved blocking issues were identified.
Review effort: Lite
Findings: None
What changed in this PR
Adds an optional iTerm2 “Open as tab” preference, reuses launched windows, and avoids scrollback prompts.
Changes:
- Adds and persists the tab preference, disabled for Terminal.app.
- Implements iTerm2 tab/window selection and launch-window reuse.
- Replaces
clearwithtput clearand adds regression tests.
| File | Description |
|---|---|
Resources/en.lproj/Preferences.xib |
Adds and positions the tab preference. |
GitXTests/PBTerminalHandlerPreferenceTests.m |
Tests preference and session behavior. |
Classes/Util/PBTerminalUtil.m |
Implements tab/window selection and launch handling. |
Classes/Util/PBTerminalUtil.h |
Declares terminal planning helpers. |
Classes/git/PBGitDefaults.m |
Stores the new preference. |
Classes/git/PBGitDefaults.h |
Exposes preference accessors. |
Classes/Controllers/PBPrefsWindowController.m |
Wires preference state and enabling. |
Classes/Controllers/PBPrefsWindowController.h |
Adds checkbox declarations. |
💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.
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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Reuse a terminal window that is already open, which is usually what is
wanted when a repository is sent to iTerm2, and fix two things the open
itself got wrong along the way.
default so the existing behaviour is unchanged
preference is on, falling back to a new window when iTerm2 has none
open
rather than asking for a second one on top
for opening a tab
tput clearin place ofclear, so opening a repository nolonger makes iTerm2 ask about clearing scrollback history
reads as belonging to "Open in Terminal:" rather than to the Gist
options below it
Screenshot
Launching iTerm2 leaves two sessions
Worth calling out because it is not obvious from the diff. Sending
createWindowWithDefaultProfileCommand:to an iTerm2 that is not runninglaunches it; iTerm2 opens a window of its own as it starts, and the event
then adds a second one on top. Both modes ended up with two sessions,
which is why the tab preference appeared to make no difference in that
case.
GitX now waits for the window iTerm2 opens for itself and uses that. If
none appears within five seconds it logs and asks for one, so a profile
configured to open no window on launch still works. The timeout is a
correctness knob rather than a comfort setting: firing it early would
reproduce the bug.
Measured on an Intel Mac with iTerm2 closed beforehand, driving the same
Scripting Bridge calls:
Test plan:
PBTerminalHandlerPreferenceTestspasses, with seven new cases: whichhandlers are offered the tab option, the window/tab/launched-window
decision for every combination of running, window open and preference,
and the shell line GitX writes into the session
clearbefore the fix went inin Terminal left the window count at 1 and took the tab count from 4
to 5; unticked, it opened a second window
clearemitsESC[3J ESC[H ESC[2Jon macOS andtput clearemitsonly
ESC[H ESC[2J, measured with xxd; no announcement appeared iniTerm2 after the change
ibtoolreports the same notices for the changed xib as for the oneit replaces
Closes #712