From 3cf56b8af3d5766210bc25202d0f82e15ce0ce6d Mon Sep 17 00:00:00 2001 From: "Jeffrey C. Ollie" Date: Sun, 6 Jul 2025 12:12:27 -0500 Subject: [PATCH 1/3] keybind: add copy_title action Fixes #7829 This will copy the terminal title to the clipboard. If the terminal title is not set it has no effect. --- src/Surface.zig | 11 +++++++++++ src/input/Binding.zig | 5 +++++ src/input/command.zig | 6 ++++++ 3 files changed, 22 insertions(+) diff --git a/src/Surface.zig b/src/Surface.zig index d9d6a3012..faba60ced 100644 --- a/src/Surface.zig +++ b/src/Surface.zig @@ -4443,6 +4443,17 @@ pub fn performBindingAction(self: *Surface, action: input.Binding.Action) !bool return false; }, + .copy_title => { + const title = self.rt_surface.getTitle() orelse return false; + + self.rt_surface.setClipboardString(title, .standard, false) catch |err| { + log.err("error copying title to clipboard err={}", .{err}); + return true; + }; + + return true; + }, + .paste_from_clipboard => try self.startClipboardRequest( .standard, .{ .paste = {} }, diff --git a/src/input/Binding.zig b/src/input/Binding.zig index c342c9cc2..6339674f8 100644 --- a/src/input/Binding.zig +++ b/src/input/Binding.zig @@ -281,6 +281,10 @@ pub const Action = union(enum) { /// If there is a URL under the cursor, copy it to the default clipboard. copy_url_to_clipboard, + /// Copy the terminal title to the clipboard. If the terminal title is not + /// set this has no effect. + copy_title, + /// Increase the font size by the specified amount in points (pt). /// /// For example, `increase_font_size:1.5` will increase the font size @@ -1005,6 +1009,7 @@ pub const Action = union(enum) { .reset, .copy_to_clipboard, .copy_url_to_clipboard, + .copy_title, .paste_from_clipboard, .paste_from_selection, .increase_font_size, diff --git a/src/input/command.zig b/src/input/command.zig index 8938835d0..434a4edf3 100644 --- a/src/input/command.zig +++ b/src/input/command.zig @@ -132,6 +132,12 @@ fn actionCommands(action: Action.Key) []const Command { .description = "Copy the URL under the cursor to the clipboard.", }}, + .copy_title => comptime &.{.{ + .action = .copy_title, + .title = "Copy Terminal Title to Clipboard", + .description = "Copy the terminal title to the clipboard. If the terminal title is not set this has no effect.", + }}, + .paste_from_clipboard => comptime &.{.{ .action = .paste_from_clipboard, .title = "Paste from Clipboard", From a23b5328a5e230fd29cb53a0f468f7eca5149c3d Mon Sep 17 00:00:00 2001 From: "Jeffrey C. Ollie" Date: Sun, 6 Jul 2025 13:12:00 -0500 Subject: [PATCH 2/3] keybind: rename copy_title to copy_title_to_clipboard Co-authored-by: Jon Parise --- src/Surface.zig | 2 +- src/input/Binding.zig | 4 ++-- src/input/command.zig | 4 ++-- 3 files changed, 5 insertions(+), 5 deletions(-) diff --git a/src/Surface.zig b/src/Surface.zig index faba60ced..30235f26f 100644 --- a/src/Surface.zig +++ b/src/Surface.zig @@ -4443,7 +4443,7 @@ pub fn performBindingAction(self: *Surface, action: input.Binding.Action) !bool return false; }, - .copy_title => { + .copy_title_to_clipboard => { const title = self.rt_surface.getTitle() orelse return false; self.rt_surface.setClipboardString(title, .standard, false) catch |err| { diff --git a/src/input/Binding.zig b/src/input/Binding.zig index 6339674f8..21edf2636 100644 --- a/src/input/Binding.zig +++ b/src/input/Binding.zig @@ -283,7 +283,7 @@ pub const Action = union(enum) { /// Copy the terminal title to the clipboard. If the terminal title is not /// set this has no effect. - copy_title, + copy_title_to_clipboard, /// Increase the font size by the specified amount in points (pt). /// @@ -1009,7 +1009,7 @@ pub const Action = union(enum) { .reset, .copy_to_clipboard, .copy_url_to_clipboard, - .copy_title, + .copy_title_to_clipboard, .paste_from_clipboard, .paste_from_selection, .increase_font_size, diff --git a/src/input/command.zig b/src/input/command.zig index 434a4edf3..84e9afc79 100644 --- a/src/input/command.zig +++ b/src/input/command.zig @@ -132,8 +132,8 @@ fn actionCommands(action: Action.Key) []const Command { .description = "Copy the URL under the cursor to the clipboard.", }}, - .copy_title => comptime &.{.{ - .action = .copy_title, + .copy_title_to_clipboard => comptime &.{.{ + .action = .copy_title_to_clipboard, .title = "Copy Terminal Title to Clipboard", .description = "Copy the terminal title to the clipboard. If the terminal title is not set this has no effect.", }}, From 7884872d4ec15b8a42f599443a337a1894d232c3 Mon Sep 17 00:00:00 2001 From: "Jeffrey C. Ollie" Date: Sun, 6 Jul 2025 14:15:11 -0500 Subject: [PATCH 3/3] keybind: don't clobber the clipboard if the title is empty --- src/Surface.zig | 1 + src/input/Binding.zig | 2 +- 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/src/Surface.zig b/src/Surface.zig index 30235f26f..372da325a 100644 --- a/src/Surface.zig +++ b/src/Surface.zig @@ -4445,6 +4445,7 @@ pub fn performBindingAction(self: *Surface, action: input.Binding.Action) !bool .copy_title_to_clipboard => { const title = self.rt_surface.getTitle() orelse return false; + if (title.len == 0) return false; self.rt_surface.setClipboardString(title, .standard, false) catch |err| { log.err("error copying title to clipboard err={}", .{err}); diff --git a/src/input/Binding.zig b/src/input/Binding.zig index 21edf2636..f76da360a 100644 --- a/src/input/Binding.zig +++ b/src/input/Binding.zig @@ -282,7 +282,7 @@ pub const Action = union(enum) { copy_url_to_clipboard, /// Copy the terminal title to the clipboard. If the terminal title is not - /// set this has no effect. + /// set or is empty this has no effect. copy_title_to_clipboard, /// Increase the font size by the specified amount in points (pt).