Repository navigation
Fix Windows-style PWD reports misclassifying local dirs as remote - #652
Merged
Merged
Conversation
On native Windows Emacs the injected logical PWD is a drive-form path (d:/repos/foo, no leading slash). MSYS bash keeps such an inherited PWD verbatim, so its OSC 7 report glues the drive spec onto the URL authority (kitty-shell-cwd://HOSTd:/repos/foo). The host/path split at the first slash then produced the bogus host "HOSTd:", which failed the local-host check and flipped default-directory to a TRAMP path on a nonexistent host - every buffer switch triggered failing remote connections. Three-part fix: - Reattach a trailing "letter:" drive spec from the authority to the path, but only when the de-glued prefix names the local host: an RFC 3986 empty-port authority ends the same way, and a foreign host must never be rewritten into a different one. A trailing colon on the local host itself is dropped as an empty port. - Normalize local Windows path spellings before the directory gate, for URL and plain (OSC 9;9) reports alike: strip the slash from /d:/foo (unresolvable by expand-file-name) and rewrite the MSYS /d/foo and Cygwin /cygdrive/d/foo mount forms to d:/foo when the rewrite names a directory - previously such reports silently stalled tracking on Windows. - Stop injecting the logical PWD on Windows: MSYS shells expect a POSIX-style PWD, and the drive-form value is what corrupted the OSC 7 report in the first place. (Emacs itself may still pass a drive-form PWD when launched from a console, which the parser repair above covers.) Fixes #650
dakra
force-pushed
the
fix/osc7-windows-drive-letter
branch
from
August 25, 2026 12:08
467ba90 to
a7f2ee3
Compare
There was a problem hiding this comment.
🟡 Changes recommended
The current trailing-colon authority handling can propagate an empty-port : into the TRAMP hostname for remote hosts, producing invalid hostnames like otherhost:.
Once you've addressed the issues Copilot identified, you can request another Copilot review.
Pull request overview
This PR fixes a Windows-specific shell integration bug where OSC 7 directory reports could be misparsed into a bogus remote TRAMP path (causing repeated failing remote connections and lag), and adds cross-platform ERT coverage for the affected cases.
Changes:
- Add Windows path normalization (slash-drive, MSYS
/d/..., Cygwin/cygdrive/d/...) and glued-drive authority repair inghostel--update-directory. - Stop injecting logical
PWDon Windows to avoid MSYS inheriting a drive-formPWDthat corrupts OSC 7. - Add new ERT tests covering glued-host, trailing-colon authority, slash-drive, MSYS/Cygwin mount paths, and plain-path (OSC 9;9) normalization.
File summaries
| File | Description |
|---|---|
lisp/ghostel.el |
Adds Windows path normalization helper and extends OSC 7 parsing/host handling; disables logical PWD injection on Windows. |
test/ghostel-shell-test.el |
Adds ERT tests for Windows OSC 7/OSC 9;9 directory tracking edge cases (glued host, slash-drive, MSYS/Cygwin paths). |
test/ghostel-environment-test.el |
Tags the logical PWD injection test as POSIX-only and adds a unit test ensuring ghostel--logical-pwd-env returns nil for remote/Windows. |
Review details
- Files reviewed: 3/3 changed files
- Comments generated: 2
- Review effort level: Lite
💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.
Comment on lines
+3556
to
+3565
| (cond | ||
| ((and (string-match "\\`\\(.*\\)\\([a-z]:\\)\\'" host) | ||
| (ghostel--local-host-p (match-string 1 host))) | ||
| (setq raw (concat (match-string 2 host) raw) | ||
| filename (concat (match-string 2 host) filename) | ||
| host (match-string 1 host))) | ||
| ;; Empty-port authority on the local host: drop the colon. | ||
| ((and (string-suffix-p ":" host) | ||
| (ghostel--local-host-p (substring host 0 -1))) | ||
| (setq host (substring host 0 -1))))))) |
dakra
force-pushed
the
fix/osc7-windows-drive-letter
branch
from
August 25, 2026 18:02
a7f2ee3 to
d8ee7a9
Compare
This branch was previously deployed
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.
Fixes #650.
On native Windows Emacs the injected logical
PWDis a drive-form path (d:/repos/foo, no leading slash). MSYS bash keeps such an inheritedPWDverbatim, so its OSC 7 report glues the drive spec onto the URL authority (kitty-shell-cwd://HOSTd:/repos/foo). The host/path split at the first slash then produced the bogus hostHOSTd:, which failed the local-host check and flippeddefault-directoryto a TRAMP path on a nonexistent host — every buffer switch triggered failing remote connections.Three-part fix:
letter:drive spec from the authority to the path, but only when the de-glued prefix names the local host: an RFC 3986 empty-port authority ends the same way, and a foreign host must never be rewritten into a different one. A trailing colon on the local host itself is dropped as an empty port./d:/foo(unresolvable byexpand-file-name) and rewrite the MSYS/d/fooand Cygwin/cygdrive/d/foomount forms tod:/foowhen the rewrite names a directory — previously such reports silently stalled tracking on Windows.PWDon Windows: MSYS shells expect a POSIX-stylePWD, and the drive-form value is what corrupted the OSC 7 report in the first place. (Emacs itself may still pass a drive-formPWDwhen launched from a console, which the parser repair above covers.)Covered by new ERT tests for the glued-host, trailing-colon-authority, slash-drive, MSYS/Cygwin, and plain-path (OSC 9;9) cases; they run in the elisp group on all platforms. Verified live on macOS (bash + fish
cdtracking unaffected); Windows verification would be appreciated — the signal isghostel-debug-infoshowing a plaind:/...default directory with no/scp:prefix.