You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
@@ -68,13 +75,17 @@ As a result, you often find yourself doing a tiresome sequence of:
68
75
69
76
macOS comes with a `pbcopy` tool that allows you to get stuff into the clipboard from the command-line. `xclip` is an alternative that works on Linux. We've already seen this at work above. Basically, we can do things like `echo foo | pbcopy` to place "foo" in the system clipboard.
70
77
71
-
tmux has a couple of handy commands related to copy mode buffers, namely `save-buffer` and `copy-pipe`. With these, you can dump the contents of a buffer to standard out.
78
+
tmux has a few handy commands related to copy mode buffers, namely `save-buffer`, `copy-pipe` and `copy-pipe-and-cancel`, the availability of which depends on the version of tmux that you are running. With these, you can dump the contents of a buffer to standard out.
79
+
80
+
In theory, combining these elements, we can add something like this to our `~/.tmux.conf`:
81
+
82
+
bind-key -T copy-mode-vi Enter send-keys -X copy-pipe-and-cancel pbcopy
72
83
73
-
In theory, combining these two elements, we can add something like this to our `~/.tmux.conf`:
84
+
or, in a version of tmux prior to 2.4 (which use `vi-copy` instead of `copy-mode-vi`, and `copy-pipe` instead of `copy-pipe-and-cancel`):
74
85
75
86
bind-key -t vi-copy Enter copy-pipe pbcopy
76
87
77
-
or, in version of tmux prior to 1.8 (which don't have the `copy-pipe` command):
88
+
or, in an even older version of tmux prior to 1.8 (which don't have the `copy-pipe-and-cancel` or `copy-pipe` commands):
78
89
79
90
bind-key y run-shell "tmux save-buffer - | pbcopy"
80
91
@@ -254,23 +265,29 @@ The flags to pass to the `executable` (defaults to `-selection clipboard` on Lin
254
265
255
266
## Configuring tmux
256
267
257
-
Now we can use a slight modification of our command from earlier. Assuming we kept the standard listen address (127.0.0.1) and port (8377), we can use a command like this to send the last-copied text whenever we hit our tmux prefix key followed by `y`:
268
+
Now we can use a slight modification of our command from earlier. Assuming we kept the standard listen address (127.0.0.1) and port (8377), we can use a command like this to send the last-copied text whenever we hit our tmux prefix key followed by `y`; here we're using netcat (`nc`) to send the contents of the buffer to the listening Clipper agent:
258
269
259
270
bind-key y run-shell "tmux save-buffer - | nc localhost 8377"
260
271
261
272
If we instead configured Clipper to listen on a UNIX domain socket at `~/.clipper.sock`, then we could do something like:
262
273
263
274
bind-key y run-shell "tmux save-buffer - | nc -U ~/.clipper.sock"
264
275
265
-
In tmux 1.8 or later, we have access to the new `copy-pipe` command and can use a single key binding to copy text into the tmux copy buffer and send it to Clipper and therefore the system clipboard at the same time:
276
+
In tmux 1.8 to 2.3, we have access to the new `copy-pipe` command and can use a single key binding to copy text into the tmux copy buffer and send it to Clipper and therefore the system clipboard at the same time:
266
277
267
278
bind-key -t vi-copy Enter copy-pipe "nc localhost 8377"
268
279
269
280
Or, for a UNIX domain socket at `~/.clipper.sock`:
270
281
271
282
bind-key -t vi-copy Enter copy-pipe "nc -U ~/.clipper.sock"
272
283
273
-
Here we're using netcat (`nc`) to send the contents of the buffer to the listening Clipper agent.
284
+
In tmux 2.4 and above, we would use:
285
+
286
+
bind-key -T copy-mode-vi Enter send-keys -X copy-pipe-and-cancel "nc localhost 8377"
287
+
288
+
Or, for a UNIX domain socket at `~/.clipper.sock`:
289
+
290
+
bind-key -T copy-mode-vi Enter send-keys -X copy-pipe-and-cancel "nc -U ~/.clipper.sock"
0 commit comments