On Fri, 12 Dec 2014 11:27:14 -0800, Suraj N. Kurapati wrote:
> Would it be possible to make `setb` and `loadb` copy to clipboard?

Attached is a rudimentary patch that enhances the `setb` and `loadb`
commands to copy to the clipboard, just like the `copy-mode` command.

Please consider adding this functionality to tmux itself; thank you!
>From 93eea3cf4c1867ab473cfaebe01517292a5f0180 Mon Sep 17 00:00:00 2001
From: "Suraj N. Kurapati" <sun...@gmail.com>
Date: Sun, 14 Dec 2014 10:30:36 -0800
Subject: [PATCH] ensure setb and loadb commands copy to clipboard

This is an ugly implementation, meant only as a proof-of-concept.
---
 cmd-load-buffer.c |  2 ++
 cmd-set-buffer.c  |  2 ++
 paste.c           | 17 +++++++++++++++++
 tmux.h            |  1 +
 4 files changed, 22 insertions(+)

diff --git a/cmd-load-buffer.c b/cmd-load-buffer.c
index 785a701..d361c59 100644
--- a/cmd-load-buffer.c
+++ b/cmd-load-buffer.c
@@ -152,6 +152,8 @@ cmd_load_buffer_callback(struct client *c, int closed, void *data)
 		free(cause);
 	}
 
+	paste_set_clipboard(pdata, psize, c->cmdq);
+
 out:
 	cmdq_continue(c->cmdq);
 }
diff --git a/cmd-set-buffer.c b/cmd-set-buffer.c
index 0ec362b..1f5d6bf 100644
--- a/cmd-set-buffer.c
+++ b/cmd-set-buffer.c
@@ -114,5 +114,7 @@ cmd_set_buffer_exec(struct cmd *self, struct cmd_q *cmdq)
 		return (CMD_RETURN_ERROR);
 	}
 
+	paste_set_clipboard(pdata, psize, cmdq);
+
 	return (CMD_RETURN_NORMAL);
 }
diff --git a/paste.c b/paste.c
index 998b975..06f962c 100644
--- a/paste.c
+++ b/paste.c
@@ -219,6 +219,23 @@ paste_rename(const char *oldname, const char *newname, char **cause)
 	return (0);
 }
 
+void
+paste_set_clipboard(char *buf, size_t len, struct cmd_q *cmdq)
+{
+	struct screen_write_ctx	ctx;
+	struct window_pane	*wp;
+
+	if (!options_get_number(&global_options, "set-clipboard"))
+		return;
+
+	if (cmd_find_pane(cmdq, NULL, NULL, &wp) == NULL)
+		return;
+
+	screen_write_start(&ctx, wp, NULL);
+	screen_write_setselection(&ctx, buf, len);
+	screen_write_stop(&ctx);
+}
+
 /*
  * Add or replace an item in the store. Note that the caller is responsible for
  * allocating data.
diff --git a/tmux.h b/tmux.h
index 61f2ca7..2189142 100644
--- a/tmux.h
+++ b/tmux.h
@@ -1688,6 +1688,7 @@ int		 paste_free_name(const char *);
 void		 paste_add(char *, size_t);
 int		 paste_rename(const char *, const char *, char **);
 int		 paste_set(char *, size_t, const char *, char **);
+void	 	 paste_set_clipboard(char *, size_t, struct cmd_q *);
 char		*paste_make_sample(struct paste_buffer *, int);
 void		 paste_send_pane(struct paste_buffer *, struct window_pane *,
 		     const char *, int);
-- 
2.1.0

------------------------------------------------------------------------------
Download BIRT iHub F-Type - The Free Enterprise-Grade BIRT Server
from Actuate! Instantly Supercharge Your Business Reports and Dashboards
with Interactivity, Sharing, Native Excel Exports, App Integration & more
Get technology previously reserved for billion-dollar corporations, FREE
http://pubads.g.doubleclick.net/gampad/clk?id=164703151&iu=/4140/ostg.clktrk
_______________________________________________
tmux-users mailing list
tmux-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/tmux-users

Reply via email to