Skip to content

Commit 0d55a1d

Browse files
authored
Introduce action for copying into clipboard (ghostty-org#7721)
This introduces an action for copying the path of a written screen/selection file into the clipboard. Pasting the path into the terminal doesn't work well if you have a program still running and opening the file outside the terminal (on macOS in TextEdit by default) isn't always a great experience. Allowing to copy the file path into the clipboard seems like a minor and hopefully uncontroversial addition. 😅
2 parents cc2c45f + ef06e3d commit 0d55a1d

4 files changed

Lines changed: 26 additions & 0 deletions

File tree

src/Surface.zig

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4845,6 +4845,11 @@ fn writeScreenFile(
48454845
const path = try tmp_dir.dir.realpath(filename, &path_buf);
48464846

48474847
switch (write_action) {
4848+
.copy => {
4849+
const pathZ = try self.alloc.dupeZ(u8, path);
4850+
defer self.alloc.free(pathZ);
4851+
try self.rt_surface.setClipboardString(pathZ, .standard, false);
4852+
},
48484853
.open => try internal_os.open(self.alloc, .text, path),
48494854
.paste => self.io.queueMessage(try termio.Message.writeReq(
48504855
self.alloc,

src/config/Config.zig

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5032,6 +5032,12 @@ pub const Keybinds = struct {
50325032
.{ .reset_font_size = {} },
50335033
);
50345034

5035+
try self.set.put(
5036+
alloc,
5037+
.{ .key = .{ .unicode = 'j' }, .mods = .{ .shift = true, .ctrl = true, .super = true } },
5038+
.{ .write_screen_file = .copy },
5039+
);
5040+
50355041
try self.set.put(
50365042
alloc,
50375043
.{ .key = .{ .unicode = 'j' }, .mods = inputpkg.ctrlOrSuper(.{ .shift = true }) },

src/input/Binding.zig

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -379,6 +379,10 @@ pub const Action = union(enum) {
379379
///
380380
/// Valid actions are:
381381
///
382+
/// - `copy`
383+
///
384+
/// Copy the file path into the clipboard.
385+
///
382386
/// - `paste`
383387
///
384388
/// Paste the file path into the terminal.
@@ -813,6 +817,7 @@ pub const Action = union(enum) {
813817
};
814818

815819
pub const WriteScreenAction = enum {
820+
copy,
816821
paste,
817822
open,
818823
};

src/input/command.zig

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -204,6 +204,11 @@ fn actionCommands(action: Action.Key) []const Command {
204204
}},
205205

206206
.write_screen_file => comptime &.{
207+
.{
208+
.action = .{ .write_screen_file = .copy },
209+
.title = "Copy Screen to Temporary File and Copy Path",
210+
.description = "Copy the screen contents to a temporary file and copy the path to the clipboard.",
211+
},
207212
.{
208213
.action = .{ .write_screen_file = .paste },
209214
.title = "Copy Screen to Temporary File and Paste Path",
@@ -217,6 +222,11 @@ fn actionCommands(action: Action.Key) []const Command {
217222
},
218223

219224
.write_selection_file => comptime &.{
225+
.{
226+
.action = .{ .write_selection_file = .copy },
227+
.title = "Copy Selection to Temporary File and Copy Path",
228+
.description = "Copy the selection contents to a temporary file and copy the path to the clipboard.",
229+
},
220230
.{
221231
.action = .{ .write_selection_file = .paste },
222232
.title = "Copy Selection to Temporary File and Paste Path",

0 commit comments

Comments
 (0)