Skip to content

Fix Windows-style PWD reports misclassifying local dirs as remote - #652

Merged
dakra merged 1 commit into
mainfrom
fix/osc7-windows-drive-letter
Aug 25, 2026
Merged

dakra merged 1 commit into
mainfrom
fix/osc7-windows-drive-letter

Conversation

@dakra

@dakra dakra commented Aug 25, 2026

Copy link
Copy Markdown
Owner

Fixes #650.

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.)

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 cd tracking unaffected); Windows verification would be appreciated — the signal is ghostel-debug-info showing a plain d:/... default directory with no /scp: prefix.

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

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

🟡 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 in ghostel--update-directory.
  • Stop injecting logical PWD on Windows to avoid MSYS inheriting a drive-form PWD that 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 thread lisp/ghostel.el Outdated
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)))))))
Comment thread test/ghostel-shell-test.el Outdated
@dakra
dakra force-pushed the fix/osc7-windows-drive-letter branch from a7f2ee3 to d8ee7a9 Compare August 25, 2026 18:02
@dakra
dakra merged commit d8ee7a9 into main Aug 25, 2026
33 checks passed
@dakra
dakra deleted the fix/osc7-windows-drive-letter branch August 25, 2026 18:14

This branch was previously deployed

1 inactive deployment
github-pages — d8ee7a9e Deployed Aug 25, 2026 by dakra via deploy #173
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.

Ghostel mistakenly treating local directory as remote on Windows

2 participants