Skip to content

Commit 9c35c04

Browse files
committed
doc: apply updates for compatibility with tmux 2.4
Closes: #10
1 parent 1923f09 commit 9c35c04

File tree

1 file changed

+27
-10
lines changed

1 file changed

+27
-10
lines changed

README.md

+27-10
Original file line numberDiff line numberDiff line change
@@ -10,18 +10,25 @@ Clipper is a macOS "launch agent" — or Linux daemon — that runs in t
1010
brew install clipper # run this outside of a tmux session
1111

1212
# Configuration for ~/.tmux.conf:
13-
# tmux < 1.8: bind <prefix>-y to forward to Clipper
14-
bind-key y run-shell "tmux save-buffer - | nc localhost 8377"
13+
14+
# tmux >= 2.4: bind "Enter" in copy mode to both copy and forward to Clipper
15+
bind-key -T copy-mode-vi Enter send-keys -X copy-pipe-and-cancel "nc localhost 8377"
1516

1617
# Or, if you are running Clipper on a UNIX domain socket:
17-
bind-key y run-shell "tmux save-buffer - | nc -U ~/.clipper.sock"
18+
bind-key -T copy-mode-vi Enter send-keys -X copy-pipe-and-cancel "nc -U ~/.clipper.sock"
1819

19-
# tmux >= 1.8: bind "Enter" in copy mode to both copy and forward to Clipper
20+
# tmux >= 1.8 and < 2.4: bind "Enter" in copy mode to both copy and forward to Clipper
2021
bind-key -t vi-copy Enter copy-pipe "nc localhost 8377"
2122

2223
# Or, if you are running Clipper on a UNIX domain socket:
2324
bind-key -t vi-copy Enter copy-pipe "nc -U ~/.clipper.sock"
2425

26+
# tmux < 1.8: bind <prefix>-y to forward to Clipper
27+
bind-key y run-shell "tmux save-buffer - | nc localhost 8377"
28+
29+
# Or, if you are running Clipper on a UNIX domain socket:
30+
bind-key y run-shell "tmux save-buffer - | nc -U ~/.clipper.sock"
31+
2532
# Configuration for ~/.vimrc:
2633
# Bind <leader>y to forward last-yanked text to Clipper
2734
nnoremap <leader>y :call system('nc localhost 8377', @0)<CR>
@@ -68,13 +75,17 @@ As a result, you often find yourself doing a tiresome sequence of:
6875

6976
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.
7077

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
7283

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`):
7485

7586
bind-key -t vi-copy Enter copy-pipe pbcopy
7687

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):
7889

7990
bind-key y run-shell "tmux save-buffer - | pbcopy"
8091

@@ -254,23 +265,29 @@ The flags to pass to the `executable` (defaults to `-selection clipboard` on Lin
254265

255266
## Configuring tmux
256267

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:
258269

259270
bind-key y run-shell "tmux save-buffer - | nc localhost 8377"
260271

261272
If we instead configured Clipper to listen on a UNIX domain socket at `~/.clipper.sock`, then we could do something like:
262273

263274
bind-key y run-shell "tmux save-buffer - | nc -U ~/.clipper.sock"
264275

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:
266277

267278
bind-key -t vi-copy Enter copy-pipe "nc localhost 8377"
268279

269280
Or, for a UNIX domain socket at `~/.clipper.sock`:
270281

271282
bind-key -t vi-copy Enter copy-pipe "nc -U ~/.clipper.sock"
272283

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"
274291

275292
## Configuring Vim
276293

0 commit comments

Comments
 (0)