feat(repl): add OSC 7 terminal cwd tracking#196
Merged
kunchenguid merged 1 commit intomainfrom Mar 14, 2026
Merged
Conversation
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #196 +/- ##
=======================================
Coverage 64.03% 64.04%
=======================================
Files 102 103 +1
Lines 13292 13301 +9
=======================================
+ Hits 8512 8519 +7
- Misses 4219 4221 +2
Partials 561 561 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
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.
Summary
Adds OSC 7 escape sequence support to the REPL loop so that terminal emulators (Terminal.app, iTerm2, etc.) can track the current working directory. This enables new tabs or windows opened from the terminal to start in the same directory as the gsh session.
Risk Assessment: 🟢 Low — Well-bounded additive feature emitting OSC 7 terminal escape sequences, with unit tests and no changes to existing logic.
Architecture
flowchart TD repl_run["REPL.Run loop (updated)"] osc["emitOSC7 (added)"] osc_test["emitOSC7 tests (added)"] executor["Executor.GetPwd (unchanged)"] terminal["term.IsTerminal check (unchanged)"] stdout["os.Stdout (unchanged)"] repl_run -->|"calls on each iteration"| osc repl_run -->|"gets working directory"| executor repl_run -->|"guards with TTY check"| terminal osc -->|"writes escape sequence to"| stdout osc_test -->|"validates"| oscKey changes made
emitOSC7function (internal/repl/osc.go): Writes theESC]7;file://HOSTNAME/path ESC\escape sequence to anio.Writer, with proper per-segment URL encoding to handle special characters (spaces,#, etc.) while preserving/separators.internal/repl/repl.go): Caches the hostname at REPL startup and emits OSC 7 before each prompt, but only when stdout is a terminal and a working directory is available.internal/repl/osc_test.go): Covers normal paths, paths with spaces, paths with#, and empty hostname scenarios.How was this tested
#, and empty hostname scenarios