diff --git a/macos/Sources/Ghostty/Ghostty.SplitNode.swift b/macos/Sources/Ghostty/Ghostty.SplitNode.swift index fba43443a..35240b5fa 100644 --- a/macos/Sources/Ghostty/Ghostty.SplitNode.swift +++ b/macos/Sources/Ghostty/Ghostty.SplitNode.swift @@ -141,6 +141,10 @@ extension Ghostty { // MARK: - Codable + enum CodingKeys: String, CodingKey { + case pwd + } + required convenience init(from decoder: Decoder) throws { // Decoding uses the global Ghostty app guard let del = NSApplication.shared.delegate, @@ -149,12 +153,16 @@ extension Ghostty { throw TerminalRestoreError.delegateInvalid } - self.init(app, nil) + let container = try decoder.container(keyedBy: CodingKeys.self) + var config = SurfaceConfiguration() + config.workingDirectory = try container.decode(String?.self, forKey: .pwd) + + self.init(app, config) } func encode(to encoder: Encoder) throws { - // We don't currently encode anything, but in the future we will - // want to encode pwd, etc... + var container = encoder.container(keyedBy: CodingKeys.self) + try container.encode(surface.pwd, forKey: .pwd) } } diff --git a/macos/Sources/Ghostty/SurfaceView.swift b/macos/Sources/Ghostty/SurfaceView.swift index a75cbe255..6ad8122a6 100644 --- a/macos/Sources/Ghostty/SurfaceView.swift +++ b/macos/Sources/Ghostty/SurfaceView.swift @@ -283,6 +283,17 @@ extension Ghostty { return ghostty_surface_needs_confirm_quit(surface) } + /// Returns the pwd of the surface if it has one. + var pwd: String? { + guard let surface = self.surface else { return nil } + let v = String(unsafeUninitializedCapacity: 1024) { + Int(ghostty_surface_pwd(surface, $0.baseAddress, UInt($0.count))) + } + + if (v.count == 0) { return nil } + return v + } + // Returns the inspector instance for this surface, or nil if the // surface has been closed. var inspector: ghostty_inspector_t? {