Compare commits

...

140 commits

Author SHA1 Message Date
Bruno Sutic acfd36e4fc
Merge pull request #167 from iloveitaly/put-with-bracketed-paste
paste buffer with bracketed paste
2023-07-19 14:42:45 +02:00
Michael Bianco 67526eff82
paste buffer with bracketed paste
this ensures the command does not automatically execute
2023-05-20 22:57:05 -06:00
Oliver Ruben Albertini 1b1a436e19
copy_pane_pwd: set tmux buffer
All the other copy commands not only set the system clipboard, but also
set the tmux buffer to have the selection. For consistency, the copy
pane PWD action should behave the same way.
2020-10-02 08:21:24 +02:00
Bruno Sutic d776f4e94d
Merge pull request #142 from jonasw234/master
Remove 'next-' string from version, fixes #140
2020-08-07 08:55:57 +02:00
Jonas Wendorf 0780e4dd95 Remove 'next-' string from version, fixes #140 2020-04-24 21:09:43 +02:00
Bruno Sutic 648005db64
Merge pull request #134 from lilalkor/versions-compare
scripts/helpers.sh: fix version compare
2019-12-02 13:46:41 +01:00
lilalkor 3db48fd468 scripts/helpers.sh: fix version compare 2019-11-28 20:31:07 +03:00
Bruno Sutic ce21dafd9a
Merge pull request #129 from kennith/update-macOS-requirement
Update macOS reattach-to-user-namespace requirement
2019-10-10 01:33:08 +02:00
Kennith Leung 9732e66fc0
Update README.md 2019-10-09 13:10:53 -07:00
Niklas Baumstark 226587cf7c Fix for WSL 2 clip.exe
Apparently clip.exe doesn't work properly with WSL 2: It doesn't exit when EOF is reached on STDIN. This is a workaround by making sure that SIGPIPE is sent on EOF.
2019-07-16 21:16:28 -04:00
Andreas Brenk c32337c164 Support wl-copy from the Wayland clipboard utilities 2019-07-12 10:02:02 -04:00
paresharma 44fc7cc7b5 Use -T instead of -t for Tmux 2.4 and above 2019-05-01 22:22:40 -04:00
Christian Höltje 63d505465f test(lint): disable bogus lint alerts 2019-05-01 22:19:53 -04:00
Christian Höltje 30bfd78006 Merge yank-with-mouse from @keidax
- Ran `shfmt` on shell code.
- Fixed ordering of `xclip` and `xsel`.

Issue #109
2018-12-04 10:34:25 -05:00
Christian Höltje c6a73eba6b run shfmt on scripts
shfmt -f . | xargs -E'\n' shfmt -w -i 4 -s
2018-08-22 10:48:18 -04:00
Christian Höltje 302a61e5d4 tmux_is_at_least: fix IFS issue and improve variable names 2018-08-22 10:24:08 -04:00
Christian Höltje c41154ecd9 travis: use docker to run bash & shellheck 2018-08-14 09:41:56 -04:00
Christian Höltje 6017d69dc4 tmux_is_at_least: fixed lint 2018-08-14 09:13:09 -04:00
Christian Höltje e401bb6413 Prefer xsel to xclip
Fixes #114
2018-08-14 09:08:06 -04:00
Gabriel Holodak 74b0ff7c92 Document @yank_action 2018-06-07 22:18:41 -04:00
Gabriel Holodak f855b93c66 Document mouse support 2018-06-07 21:59:15 -04:00
Gabriel Holodak cba7f2c04f PR feedback: add default local value 2018-06-07 21:58:00 -04:00
Gabriel Holodak 8464dad600 Add option to disable mouse bindings 2018-05-28 14:58:32 -04:00
Gabriel Holodak d3a87359ab Add mouse bindings and separate selection option 2018-05-28 14:55:29 -04:00
Christian Höltje e8a03cf41d
Merge pull request #104 from kaliberr44/master
yank default action for TMUX > 2.4 + MouseDragEnd1Pane
2018-03-18 19:14:39 -04:00
Christian Höltje 19b1123498 travis: use pushover for notices 2018-02-01 22:11:37 -05:00
Christian Höltje fd8000238b v2.3.0 2018-02-01 22:09:43 -05:00
Robert Przybylowicz ab918db34a Removed MouseDragEnd1Pane and reverted yank deafult action to copy-pipe-and-cancel 2018-01-12 20:32:42 +01:00
Robert Przybylowicz 8e99f32479 yank action + MouseDragEnd1Pane yank 2017-07-05 21:03:26 +02:00
Christian Höltje feb9611b7d Add @override_copy_command to force copy command.
Fixes #90
2017-06-07 00:48:32 -04:00
Christian Höltje 68c5c7ca6f changelog: added PR 89 2017-05-19 22:05:29 -04:00
Christian Höltje 80676ffbf4 readme: mention default for @yank_selection 2017-05-19 21:51:29 -04:00
Christian Höltje 53796467b8 Merge pull request #89 from maximbaz/make-tmux-is-at-least-support-build-from-master
utils: make tmux_is_at_least support "master" as version
2017-05-19 21:32:04 -04:00
Christian Höltje 14f588edbe Merge branch 'master' into make-tmux-is-at-least-support-build-from-master 2017-05-19 21:30:19 -04:00
Christian Höltje 1c50f31c93 utils: fix indentation 2017-05-19 21:24:40 -04:00
Maxim Baz b32f951c27 Make tmux_is_at_least support master version 2017-05-16 20:49:57 +02:00
Christian Höltje e6e825186e Merge pull request #88 from edi9999/fix-copy-line
Fix copyline for tmux 2.4
2017-05-09 11:40:18 -04:00
Edgar HIPP a8f20b314f Fix copyline for tmux 2.4
With the current implementation, if your shell is :

$ echo 'foo'

your cursor is at the end of the line, it will copy `$ echo 'foo'` on
tmux 2.4, and `echo 'foo'` on tmux 2.3 and below.

This normalizes the behavior on both versions so that only `echo 'foo'`
is copied
2017-05-09 08:28:56 +02:00
Christian Höltje 15b998050b readme: clarified need for reattach
Closes #73 #31
2017-05-06 00:27:43 -04:00
Christian Höltje 88e74c0fe1 Set theme jekyll-theme-slate 2017-05-05 23:38:27 -04:00
Christian Höltje 54c8bd1cd0 readme: badges 2017-05-05 23:37:07 -04:00
Christian Höltje 3219c86ed2 helpers: shellcheck lint 2017-05-05 23:28:23 -04:00
Christian Höltje 65a6d1df70 travis: use stock bash 2017-05-05 23:26:04 -04:00
Christian Höltje 10867a4f58 travis: getting latest shellcheck is hard
Trying instructions from https://github.com/koalaman/shellcheck
2017-05-05 23:24:25 -04:00
Christian Höltje 9dbbba46e8 travis: another try 2017-05-05 23:01:30 -04:00
Christian Höltje d6346c8c34 travis: added syntax and shellcheck 2017-05-05 22:59:07 -04:00
Christian Höltje 661cede866 changelog: yank-line does not care about shell_mode 2017-05-05 22:39:49 -04:00
Christian Höltje 0db3e88f33 rename tmux-is-at-least with _ 2017-05-05 22:34:40 -04:00
Christian Höltje e012849621 copy_line: simpler code for tmux 2.4 2017-05-05 22:32:53 -04:00
Christian Höltje 075f56e365 more lint 2017-05-05 22:16:07 -04:00
Christian Höltje 47b7380537 Explain how to use set-clipboard with xterm and iTerm2
Closes #51
2017-05-05 22:03:02 -04:00
Christian Höltje ab9218c987 helpers: more lint 2017-05-05 21:40:52 -04:00
Christian Höltje 6396642871 lint: Declare and assign separately
…to avoid masking return values
2017-05-05 00:29:59 -04:00
Christian Höltje f30926f150 normalized indentation in all scripts 2017-05-05 00:25:22 -04:00
Christian Höltje c5ccf91d48 readme: fixed title 2017-05-04 23:47:58 -04:00
Christian Höltje 279e7cf9e5 readme: cleanup and reformatting. 2017-05-04 23:45:24 -04:00
Christian Höltje 60291c58b2 readme: reflowed with pandoc 2017-05-04 22:49:48 -04:00
Christian Höltje 58932c9b8c changelog: use http://keepachangelog.com/ format 2017-05-04 22:40:05 -04:00
Christian Höltje ce331d4e17 Reformatted CHANGELOG
Also fixed some minor typos.
2017-05-04 22:07:48 -04:00
Christian Höltje 68e2e1e200 tell github what programming languages to ignore 2017-05-04 12:10:41 -04:00
Christian Höltje bd8c664085 Merge pull request #79 from lukewang1024/feature/WSL-support
Use clip.exe if exists for copying to Windows clipboard in WSL.
2017-05-04 11:44:15 -04:00
Christian Höltje 505383854f Merge pull request #85 from edi9999/master
Support tmux 2.4 for copy_line
2017-05-04 11:43:56 -04:00
Christian Höltje 359e50a1c2 Fix <= 2.3 support
I have no idea what I was smoking when I made the 2.4 and pre-2.4 code
the same.

Closes #83
2017-05-04 11:41:32 -04:00
Edgar HIPP adda216aa0 Support tmux 2.4 for copy_line 2017-04-29 17:05:43 +02:00
Bruno Sutic 21c3ba7f84 Merge pull request #82 from docwhat/pr/tmux-2.4
support tmux 2.4
2017-04-25 04:07:33 +02:00
Christian Höltje 375fbd8913 support tmux 2.4
TMUX has changed the way bind-keys works in version 2.4+
This change supports both older and newer versions.

Closes #76
2017-04-21 15:16:59 -04:00
Christian Höltje 896ecf9074 Added tmux-is-at-least method for version checking 2017-04-21 15:15:34 -04:00
Luke Wang fe10415ba0 Use clip.exe if exists for copying to Windows clipboard in WSL. 2017-03-28 19:52:51 +08:00
Bruno Sutic e306c645b0 Merge pull request #52 from leoalekseyev/master
Adding -b flag to run-shell commands
2016-03-05 15:01:10 +01:00
Leo Alekseyev 7528b7b4f2 Adding -b flag to run-shell commands
This prevents tmux clients from becoming unresponsive until the xclip
process is killed (happens with tmux 2.1 under Linux). See following
for details:
http://unix.stackexchange.com/questions/77355/tmux-xclip-copy-no-longer-working
2016-03-04 01:07:04 -08:00
Bruno Sutic ee9a60a9b5 Merge pull request #47 from qstrahl/patch-1
Add *.png binary to gitattributes
2015-11-19 14:22:54 +01:00
Quinn Strahl a3f4a22c10 Add *.png binary to gitattributes
core.autocrlf can do some really annoying stupid stuff otherwise, leaving local png files in a permanently modified state and making updating with tpm impossible
2015-11-18 13:20:15 -05:00
Bruno Sutic dc9853942b
Better use of constants 2015-10-12 14:25:54 +02:00
Bruno Sutic 2e82b583ff
Update vagrant provisioning script 2015-10-12 14:10:35 +02:00
Bruno Sutic 047e71f9fb
Copy pane current dir feature 2015-10-12 13:54:27 +02:00
Bruno Sutic 82e65a84dd
v2.2.0 2015-10-12 13:27:40 +02:00
Bruno Sutic 7499e6d5e1
Cygwin support via 'putclip' 2015-10-08 16:30:50 +02:00
Bruno Sutic 9a4d1ccbd0
Explicitly set 'Vagrantfile' eol to LF 2015-10-08 14:26:57 +02:00
Bruno Sutic 41b6a623ca
Better cygwin support 2015-10-08 14:24:52 +02:00
Bruno Sutic 7cabab6a50 Merge pull request #44 from netei/master
Add support for custom copy command
2015-09-28 17:42:41 +02:00
HIPP Edgar (PRESTA EXT) a21e5a027c Add support for custom copy command 2015-09-22 09:20:57 +02:00
Bruno Sutic 6e1a5f1358
Update plugin installation instructions 2015-08-10 20:43:17 +02:00
Bruno Sutic 13a8219119
v2.1.0 2015-06-17 11:56:28 +02:00
Bruno Sutic 9781bf1df8
Update readme 2015-06-17 11:55:52 +02:00
Bruno Sutic dc2e37ecdc
Deprecate 2015-06-17 11:40:17 +02:00
Bruno Sutic df107d7f3c
Document shell vi mode support 2015-06-17 11:39:21 +02:00
Bruno Sutic 0f52470e02 Merge pull request #37 from xnaveira/master
Added shell vi mode compatibility
2015-06-17 10:53:19 +02:00
Xavier Naveira 61f5da39e9 Changed vi mode commands for beginning and end of line by Bruno's suggestion 2015-06-17 10:42:33 +02:00
Xavier Naveira 4d521c1363 Added shell vi mode compatibility 2015-06-17 10:04:02 +02:00
Bruno Sutic 93749131a8
Note about emacs key bindings in the readme
Fixes #33
2015-05-12 16:11:27 +02:00
Bruno Sutic 7cbc38056f
Update changelog 2015-03-26 14:52:42 +01:00
Bruno Sutic 4041101c12
Update comment 2015-03-26 14:52:37 +01:00
Bruno Sutic 9630abb55d Merge pull request #32 from bosr/reattach
check if reattach is needed
2015-03-26 12:51:22 +01:00
Romain Bossart a613c625e3 update README 2015-03-26 07:48:13 +01:00
Romain Bossart a8d0df4d6a even simpler check 2015-03-26 07:36:09 +01:00
Romain Bossart d09dde2f24 bugfix 2015-03-25 23:29:02 +01:00
Romain Bossart f3dcea420c check if reattach is needed 2015-03-25 14:18:09 +01:00
Bruno Sutic ae65528a1d
Another readme update 2015-02-20 14:32:08 +01:00
Bruno Sutic 371b1b54ae
Readme update 2015-02-20 14:29:52 +01:00
Bruno Sutic abab655700
Update the changelog 2015-01-29 16:31:26 +01:00
Bruno Sutic 04ce0b9451 Merge pull request #26 from ctjhoa/master
Add xsel support
2015-01-29 16:30:07 +01:00
Bruno Sutic 00f0d4fc31 Merge pull request #30 from calvinchengx/master
Add simple instruction for MacPorts
2015-01-16 00:33:52 +01:00
Calvin Cheng 793ef6928e You can get reattach-to-user-namespace in MacPorts using tmux-pasteboard package too 2015-01-14 14:56:47 +08:00
Bruno Sutic 41f060e087
v2.0.0 2014-12-06 23:53:50 +01:00
Bruno Sutic 0d212c2c3d
Change "put selection" key binding to Y
Previously this was `Ctrl-y` but that overrode the default vi-copy mode
key binding.

Closes #27
2014-12-06 23:40:37 +01:00
Bruno Sutic c41a84e1b6
v1.0.0 2014-12-06 23:13:20 +01:00
Bruno Sutic 86842f2f8e
Update the readme 2014-11-27 13:35:09 +01:00
Camille TJHOA 1bb7effdf1 Fix xsel command & update README 2014-11-22 13:34:47 +01:00
Camille TJHOA 6ec89ace31 fix README 2014-11-21 14:34:43 +01:00
Camille TJHOA fbca231be2 Add xsel support 2014-11-21 14:30:07 +01:00
Bruno Sutic 23d654e560 Merge pull request #25 from duffytilleman/master
Add note to readme on mouse support
2014-11-09 17:46:17 +01:00
duffytilleman f5dbbde95f Add note to readme on mouse support 2014-11-05 17:17:30 -08:00
Bruno Sutic f0e1d227f4 Merge pull request #20 from janko-m/yank-xclip-issue
First check for pbcopy, then for xclip
2014-09-04 21:44:16 +02:00
Janko Marohnić f5e753e5f2 First check for pbcopy, then for xclip
Some Mac users may have xclip installed, and there are some cases where
xclip isn't working properly, so we just ensure here that Mac users will
always use pbcopy, and Linux users xclip.

Fixes #19.
2014-09-04 20:08:02 +02:00
Bruno Sutic 346ad27c26 Add Vagrant config for testing on linux 2014-08-04 23:04:02 +02:00
Bruno Sutic db4babe606 Add gitignore 2014-08-04 23:03:14 +02:00
Bruno Sutic bd862f9f1d Update README to show how to update xclip selection on Linux 2014-08-04 22:44:01 +02:00
Shawn Siefkas 0b323a16df Adding @yank_selection option to override xclip selection
Closes #18
2014-08-04 22:28:50 +02:00
Bruno Sutic d9af5dba16 Update README related plugins list 2014-08-03 14:53:25 +02:00
Bruno Sutic 77ec500b7c Display error message if plugin dependencies not installed
Fixes #16
2014-08-02 18:47:15 +02:00
Bruno Sutic 5101a6f3c6 Update video/README.md 2014-07-31 11:47:57 +02:00
Sencer Selcuk c4f7c78f41 specify clipboard explicitly for xclip
otherwise it doesn't work. (didn't test if this works in systems other than my own
machine which is Ubuntu)
2014-07-31 11:24:49 +02:00
Bruno Sutic 26c3ede036 Update changelog 2014-07-31 00:31:48 +02:00
Bruno Sutic 5b66e3dff5 Update video/README.md 2014-07-31 00:10:21 +02:00
Bruno Sutic 775531c514 Update changelog 2014-07-30 23:59:55 +02:00
Bruno Sutic a29aa77cf9 Remove screencast from the project because its too big to download 2014-07-30 23:52:30 +02:00
Bruno Sutic 925e1065e4 Simplify readme 2014-07-29 20:29:51 +02:00
Bruno Sutic 417457a84a v0.0.4 2014-07-29 18:27:41 +02:00
Bruno Sutic f0332c13a1 Show screencast in the readme 2014-07-29 18:27:11 +02:00
Bruno Sutic 476785eed3 Add video/README.md 2014-07-29 18:24:14 +02:00
Bruno Sutic 0465cf3bb0 Import a screencast for the project
Closes #9
2014-07-29 17:47:57 +02:00
Bruno Sutic 96d3078f68 Add screencast script 2014-07-29 17:43:57 +02:00
Bruno Sutic dfddfcb31e Update readme to reflect github organization change 2014-07-28 17:45:24 +02:00
Bruno Sutic 76a5c8485f Bump version 2014-06-29 14:18:25 +02:00
Bruno Sutic ea13a18a5d Bugfix: copy line binding never yanks newlines
This addresses a tmux/bash issue that occurs for commands with multiple
lines. When 'C-e' is pressed in a command, this confuses tmux so
newlines are yanked in copy-mode.

When a user wants to line-yank multiple-line command he is better off
when newlines aren't yanked.
This commit reliably enables this.

Fixes #13
2014-06-29 14:13:27 +02:00
Bruno Sutic 2fa5010bf4 Code cleanup
Removed lines weren't really used.
2014-06-29 12:18:23 +02:00
Bruno Sutic 144a849901 Add a readme entry about yank-line support for remote shells
Closes #12
2014-06-28 01:11:11 +02:00
Bruno Sutic bed68528d9 Bugfix: line yank doesn't work when in last pane line
When the current command line is the last/bottom line in the scrollback
buffer, then jumping to the bottom of the buffer:
- stays in the current line
- goes to the start of current line

This is, of course, not desired bc we get the wrong result.

The fix is to just 'down' movement in copy mode. The down movement
preserves cursor column.

Fixes #11.
2014-06-28 00:50:35 +02:00
Bruno Sutic 8a0c06e1fe Adds wait time for 'yank line' when running remote shell
If 'yank line' is tried when running in a remote shell (ssh) with
latency, the result will not be good.
I consistently yanked only the *last character* in the command.
This is due to latency: yank line feature works faster than the cursor
is moved in the remote shell.

To fix this issue, if remote shell is detected (ssh or mosh) wait time
is added to compensate for network latency.
Wait time of '0.2s' seemed to give good results, but at the end, wait of
'0.4s' is set. This should be more robust and allow for even greater
latency (I only wonder how could anyone work with that).
2014-06-27 12:42:33 +02:00
Bruno Sutic 9d22eccee7 Readme updates 2014-06-26 15:53:43 +02:00
19 changed files with 1093 additions and 194 deletions

24
.editorconfig Normal file
View file

@ -0,0 +1,24 @@
# EditorConfig: http://EditorConfig.org
root = true
[*]
end_of_line = lf
insert_final_newline = true
charset = utf-8
[*.md]
max_line_length = 76
indent_size = 4
trim_trailing_whitespace = true
[Vagrantfile]
indent_style = space
indent_size = 2
trim_trailing_whitespace = true
[{*.sh,*.tmux}]
indent_style = space
indent_size = 4
trim_trailing_whitespace = true

11
.gitattributes vendored Normal file
View file

@ -0,0 +1,11 @@
# The linguist directives are for https://github.com/github/linguist
*.md text eol=lf whitespace=blank-at-eol
*.sh text eol=lf whitespace=blank-at-eol diff=php
*.tmux text eol=lf whitespace=blank-at-eol diff=php
Vagrantfile text eol=lf linguist-vendored
video/* linguist-documentation
# Binary Types
*.png binary

1
.gitignore vendored Normal file
View file

@ -0,0 +1 @@
.vagrant/

17
.travis.yml Normal file
View file

@ -0,0 +1,17 @@
sudo: required
language: bash
services:
- docker
script:
- "./citest"
notifications:
email: false
pushover:
on_success: change
on_failure: always
api_key:
secure: gWoqAqGyBbO6mcKbHkt29jJZ7ElOfct2C5WPfliBARl8ImCE0HE6CEGdK25i29mjfIxXWp3HITsRawuauZDN8nCZ9srO+0wr7OWAcZuhDW6mDmKNLX2y4eR4lK21MsMpLIHqA48hYXkHVKSHR7TDG88A/0MRXoTb5gcuPDJMqPk=
users:
secure: dIUBBbi8R7cOcwBQ8guLsq+M8vBXcSAu9vKUVEqToSHoWap4fTl4QSZpyhzxLy6uSNRwg1u20xVSlEAPee2Z+efzZQtA0I9bRTkcAMbzH65+sWKgMsEMJoHrqlCr7FvX4c+UMW9sWlRLoH52oN3ilCQNy2beI8mWqE4gAGxD4aA=

View file

@ -1,13 +1,132 @@
# Changelog
Change Log
==========
### master
[master]
--------
### v0.0.2, Jun 25, 2014
### Added
- updated readme
- for OS X, also check if 'reattach-to-user-namespace' is installed
- add a feature for copying current command line to clipboard
- Mouse support, controlled by `yank_with_mouse` and `yank_selection_mouse`
(@keidax)
### v0.0.1, Jun 24, 2014
[v2.3.0] 2018-02-01
-------------------
- first working version
### Added
- Tmux 2.4 support (@docwhat, @edi9999)
- Windows Subsystem for Linux (WSL) support via `clip.exe` (@lukewang1024)
- "copy pane current directory" feature (@bruno-)
- `yank_line` and `yank_pane_pwd` fork to prevent xclip from hanging Tmux (@leoalekseyev)
* `yank_line` no longer cares if you use emacs or vi in copy-mode.
### Fixed
- Detect git builds of tmux version ≥ 2.4 (@maximbaz PR#89)
[v2.2.0] 2015-10-12
-------------------
### Added
- Support for custom copy command (if `xclip` and others aren't
accessible, and you want to have your custom copy command)
- Cygwin support via `putclip` command
[v2.1.0] 2015-06-17
-------------------
### Added
- Add support for `xsel` on Linux (@ctjhoa)
- Support for shell `vi` mode (@xnaveira)
### Updated
- Make `reattach-to-user-namespace` on OS X optional (@bosr)
- Deprecate <kbd>Alt</kbd><kbd>y</kbd>
[v2.0.0] 2014-12-06
-------------------
### Fixed
- Change copy mode "put selection" key binding to <kbd>Y</kbd> so that vi
mode <kbd>Control</kbd><kbd>y</kbd> is not overridden.
[v1.0.0] 2014-12-06
-------------------
### Added
- Show error message if plugin dependencies aren't installed.
- Vagrant setup for manually testing Linux.
### Updated
- `README`
- Related plugin list
- Instructions on updating `xclip` for Linux.
### Removed
- The screen-cast is moved into `screencast` branch.
[v0.0.4] 2014-07-29
-------------------
### Updated
- `README` documentation; including a screen-cast.
[v0.0.3] 2014-06-29
-------------------
### Added
- Wait when doing "yank line" when using a remote shell (`ssh`, `mosh`) to
ensure screen is updated.
### Fixed
- Handle `yank-line` when used on the last line of buffer: copy multiple
lines.
- `yank-line` never yanks 'newline' char for multiple-line commands in
shell (this is actually tmux/bash bug).
### Updated
- Code cleanup.
[v0.0.2] 2014-06-25
-------------------
### Updated
- `README`
### Added
- In OS X: Check if `reattach-to-user-namespace` is installed.
- "copy current command line" feature.
[v0.0.1] 2014-06-24
-------------------
- First working version.
Notes
-----
This change log is kept in <http://keepachangelog.com/> format.
[master]: https://github.com/tmux-plugins/tmux-yank/compare/v2.3.0...HEAD
[v2.3.0]: https://github.com/tmux-plugins/tmux-yank/compare/v2.2.0...v2.3.0
[v2.2.0]: https://github.com/tmux-plugins/tmux-yank/compare/v2.1.0...v2.2.0
[v2.1.0]: https://github.com/tmux-plugins/tmux-yank/compare/v2.0.0...v2.1.0
[v2.0.0]: https://github.com/tmux-plugins/tmux-yank/compare/v1.0.0...v2.0.0
[v1.0.0]: https://github.com/tmux-plugins/tmux-yank/compare/v0.0.4...v1.0.0
[v0.0.4]: https://github.com/tmux-plugins/tmux-yank/compare/v0.0.3...v0.0.4
[v0.0.3]: https://github.com/tmux-plugins/tmux-yank/compare/v0.0.2...v0.0.3
[v0.0.2]: https://github.com/tmux-plugins/tmux-yank/compare/v0.0.1...v0.0.2
[v0.0.1]: https://github.com/tmux-plugins/tmux-yank/commits/v0.0.1

View file

@ -1,4 +1,5 @@
Copyright (C) 2014 Bruno Sutic
Copyright (C) 2014, 2017 Bruno Sutic
Copyright (C) 2017 Christian Höltje
Permission is hereby granted, free of charge, to any person obtaining
a copy of this software and associated documentation files (the "Software"),

305
README.md
View file

@ -1,68 +1,289 @@
# Tmux Yank
[![Build
Status](https://travis-ci.org/tmux-plugins/tmux-yank.svg?branch=master)](https://travis-ci.org/tmux-plugins/tmux-yank)
[![GitHub
release](https://img.shields.io/github/release/tmux-plugins/tmux-yank.svg)](https://github.com/tmux-plugins/tmux-yank/releases)
[![GitHub
issues](https://img.shields.io/github/issues/tmux-plugins/tmux-yank.svg)](https://github.com/tmux-plugins/tmux-yank/issues)
Enables copying to system clipboard in Tmux. Works on Linux and OS X.
tmux-yank
=========
Key bindings:
- `prefix + y` - copies text from the command line to clipboard. It does **not**
mess up the command you're writing.<br/>
This feature works for any shell or repl where `readline` is enabled.
To test this check if `Ctrl-a` binding takes you to the start of the line.
This should work for all popular shells/repls, but please try out it for your
specific scenario.<br/>
Tested and working for: `bash`, `zsh` (with `bindkey -e`), `tcsh`, `irb`,
`pry`, `node`, `psql`, `python`, `php -a`, `coffee`
Copy to the system clipboard in [`tmux`](https://tmux.github.io/).
**copy mode** bindings:
- `y` - copy selection to system clipboard
- `Ctrl-y` - "put" selection - equivalent to copying a selection, and pasting it to the command line
- `Alt-y` - performs both of the above: copy to system clipboard and
put to command line
Supports:
#### OS X requirements
- Linux
- macOS
- Cygwin
- Windows Subsystem for Linux (WSL)
- [reattach-to-user-namespace](https://github.com/ChrisJohnsen/tmux-MacOSX-pasteboard)<br/>
If you already don't have this installed, then:
`$ brew install reattach-to-user-namespace`.
Installing
----------
#### Linux requirements
### Via TPM (recommended)
- `xclip` command<br/>
You most likely already have `xclip`, but if not install:
- Debian / Ubuntu: `$ sudo apt-get install xclip`
- Red hat / CentOS: `$ yum install xclip`
The easiest way to install `tmux-yank` is via the [Tmux Plugin
Manager](https://github.com/tmux-plugins/tpm).
### Installation with [Tmux Plugin Manager](https://github.com/bruno-/tpm) (recommended)
1. Add plugin to the list of TPM plugins in `.tmux.conf`:
Add plugin to the list of TPM plugins in `.tmux.conf`:
``` tmux
set -g @plugin 'tmux-plugins/tmux-yank'
```
set -g @tpm_plugins " \
bruno-/tpm \
bruno-/tmux_yank \
"
Hit `prefix + I` to fetch the plugin and source it. You should now be able to
use the plugin.
2. Use <kbd>prefix</kbd><kbd>I</kbd> install `tmux-yank`. You should now
be able to `tmux-yank` immediately.
3. When you want to update `tmux-yank` use <kbd>prefix</kbd><kbd>U</kbd>.
### Manual Installation
Clone the repo:
1. Clone the repository
$ git clone https://github.com/bruno-/tmux_yank ~/clone/path
``` sh
$ git clone https://github.com/tmux-plugins/tmux-yank ~/clone/path
```
Add this line to the bottom of `.tmux.conf`:
2. Add this line to the bottom of `.tmux.conf`
``` tmux
run-shell ~/clone/path/yank.tmux
```
Reload TMUX environment:
3. Reload the `tmux` environment
# type this in terminal
``` sh
# type this inside tmux
$ tmux source-file ~/.tmux.conf
```
You should now be able to use the plugin.
You should now be able to use `tmux-yank` immediately.
### Other Tmux goodies
Requirements
------------
Tmux yank works well with [tmux copycat](https://github.com/bruno-/tmux_copycat).
In order for `tmux-yank` to work, there must be a program that store data in
the system clipboard.
### macOS
- [`reattach-to-user-namespace`](https://github.com/ChrisJohnsen/tmux-MacOSX-pasteboard)
**Note**: Some versions of macOS (aka OS X) have been reported to work
without `reattach-to-user-namespace`. It doesn't hurt to have it installed.
- OS X 10.8: Mountain Lion *required*
- OS X 10.9: Mavericks *required*
- OS X 10.10: Yosemite *not required*
- OS X 10.11: El Capitan *not required*
- macOS 10.12: Sierra *required*
- macOS 10.14: Mojave - *required*
- macOS 10.15: Catalina - *not required*
The easiest way to use `reattach-to-user-namespace` with `tmux` is use to
use the [`tmux-sensible`](https://github.com/tmux-plugins/tmux-sensible)
plugin.
To use it manually, use:
``` tmux
# ~/.tmux.conf
set-option -g default-command "reattach-to-user-namespace -l $SHELL"
```
If you have `tmux` 1.5 or newer and are using
[iTerm2](https://www.iterm2.com/) version 3 or newer then the <kbd>y</kbd>
in `copy-mode` and mouse selection will work without `tmux-yank`.
To enable this:
1. Go into iTerm2's preferences.
2. Go to the "General" tab.
3. Check "Applications in terminal may access clipboard"
4. In `tmux`, ensure `set-clipboard` is turned on:
``` sh
$ tmux show-options -g -s set-clipboard
set-clipboard on
```
#### [HomeBrew](https://brew.sh/) (recommended)
``` sh
$ brew install reattach-to-user-namespace
```
#### MacPorts
``` sh
$ sudo port install tmux-pasteboard
```
### Linux
- `xsel` (recommended) or `xclip` (for X).
- `wl-copy` from [wl-clipboard](https://github.com/bugaevc/wl-clipboard) (for Wayland)
If you have `tmux` 1.5 or newer and are using `xterm`, the <kbd>y</kbd> in
`copy-mode` and mouse selection will work without `tmux-yank`. See the
`tmux(1)` man page entry for the `set-clipboard` option.
#### Debian & Ubuntu
``` sh
$ sudo apt-get install xsel # or xclip
```
#### RedHat & CentOS
``` sh
$ sudo yum install xsel # or xclip
```
### Cygwin
- (*optional*) `putclip` which is part of the `cygutils-extra` package.
### Windows Subsystem for Linux (WSL)
- `clip.exe` is shipped with Windows Subsystem for Linux.
Configuration
-------------
### Key bindings
- Normal Mode
- <kbd>prefix</kbd><kbd>y</kbd> — copies text from the command line
to the clipboard.
Works with all popular shells/repls. Tested with:
- shells: `bash`, `zsh` (with `bindkey -e`), `tcsh`
- repls: `irb`, `pry`, `node`, `psql`, `python`, `php -a`,
`coffee`
- remote shells: `ssh`, [mosh](http://mosh.mit.edu/)
- vim/neovim command line (requires
[vim-husk](https://github.com/bruno-/vim-husk) or
[vim-rsi](https://github.com/tpope/vim-rsi) plugin)
- <kbd>prefix</kbd><kbd>Y</kbd> — copy the current pane's current
working directory to the clipboard.
- Copy Mode
- <kbd>y</kbd> — copy selection to system clipboard.
- <kbd>Y</kbd> (shift-y) — "put" selection. Equivalent to copying a
selection, and pasting it to the command line.
### Default and Preferred Clipboard Programs
tmux-yank does its best to detect a reasonable choice for a clipboard
program on your OS.
If tmux-yank can't detect a known clipboard program then it uses the
`@custom_copy_command` tmux option as your clipboard program if set.
If you need to always override tmux-yank's choice for a clipboard program,
then you can set `@override_copy_command` to force tmux-yank to use whatever
you want.
Note that both programs _must_ accept `STDIN` for the text to be copied.
An example of setting `@override_copy_command`:
``` tmux
# ~/.tmux.conf
set -g @custom_copy_command 'my-clipboard-copy --some-arg'
# or
set -g @override_copy_command 'my-clipboard-copy --some-arg'
```
### Linux Clipboards
Linux has several cut-and-paste clipboards: `primary`, `secondary`, and
`clipboard` (default in tmux-yank is `clipboard`).
You can change this by setting `@yank_selection`:
``` tmux
# ~/.tmux.conf
set -g @yank_selection 'primary' # or 'secondary' or 'clipboard'
```
With mouse support turned on (see below) the default clipboard for mouse
selections is `primary`.
You can change this by setting `@yank_selection_mouse`:
``` tmux
# ~/.tmux.conf
set -g @yank_selection_mouse 'clipboard' # or 'primary' or 'secondary'
```
### Controlling Yank Behavior
By default, `tmux-yank` will exit copy mode after yanking text. If you wish to
remain in copy mode, you can set `@yank_action`:
``` tmux
# ~/.tmux.conf
set -g @yank_action 'copy-pipe' # or 'copy-pipe-and-cancel' for the default
```
### Mouse Support
`tmux-yank` has mouse support enabled by default. It will only work if `tmux`'s
built-in mouse support is also enabled (with `mouse on` since `tmux` 2.1, or
`mode-mouse on` in older versions).
To yank with the mouse, click and drag with the primary button to begin
selection, and release to yank.
If you would prefer to disable this behavior, or provide your own bindings for
the `MouseDragEnd1Pane` event, you can do so with:
``` tmux
# ~/.tmux.conf
set -g @yank_with_mouse off # or 'on'
```
If you want to remain in copy mode after making a mouse selection, set
`@yank_action` as described above.
### vi mode support
If using `tmux` 2.3 or older *and* using vi keys then you'll have add the
following configuration setting:
``` tmux
# ~/.tmux.conf
set -g @shell_mode 'vi'
```
This isn't needed with `tmux` 2.4 or newer.
### Screen-cast
[![screencast
screenshot](/video/screencast_img.png)](https://vimeo.com/102039099)
**Note**: The screen-cast uses <kbd>Control</kbd><kbd>y</kbd> for
"put selection". Use <kbd>Y</kbd> in `v2.0.0` and later.
### Other tmux plugins
- [tmux-copycat](https://github.com/tmux-plugins/tmux-copycat) - a plugin
for regular expression searches in tmux and fast match selection
- [tmux-open](https://github.com/tmux-plugins/tmux-open) - a plugin for
quickly opening highlighted file or a URL
- [tmux-continuum](https://github.com/tmux-plugins/tmux-continuum) -
automatic restoring and continuous saving of tmux environment.
### License

10
Vagrantfile vendored Normal file
View file

@ -0,0 +1,10 @@
VAGRANTFILE_API_VERSION = '2'
Vagrant.configure(VAGRANTFILE_API_VERSION) do |config|
config.vm.box = 'precise32'
config.vm.box_url = 'http://files.vagrantup.com/precise32.box'
config.vm.provision 'shell', path: 'vagrant_provisioning.sh'
config.ssh.forward_x11 = true
end

1
_config.yml Normal file
View file

@ -0,0 +1 @@
theme: jekyll-theme-slate

30
citest Executable file
View file

@ -0,0 +1,30 @@
#!/bin/bash
set -euo pipefail
cd "$(dirname "$0")"
bash_scripts=(
yank.tmux
scripts/*.sh
)
set -x
docker run \
--rm \
--volume="${PWD}:/mnt:ro" \
--workdir="/mnt" \
bash:latest \
bash -Dn "${bash_scripts[@]}"
docker run \
--rm \
--volume="${PWD}:/mnt:ro" \
--workdir="/mnt" \
koalaman/shellcheck:stable \
--shell=bash \
--external-sources \
--color=always \
"${bash_scripts[@]}"
# EOF

View file

@ -1,75 +1,111 @@
#!/usr/bin/env bash
CURRENT_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
CURRENT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
HELPERS_DIR="$CURRENT_DIR"
TMUX_COPY_MODE=""
source "$CURRENT_DIR/key_binding_helpers.sh"
REMOTE_SHELL_WAIT_TIME="0.4"
COPY_COMMAND="$*"
# shellcheck source=scripts/helpers.sh
source "${HELPERS_DIR}/helpers.sh"
# sets a TMUX_COPY_MODE that is used as a global variable
get_tmux_copy_mode() {
TMUX_COPY_MODE="$(tmux show-option -gwv mode-keys)"
TMUX_COPY_MODE="$(tmux show-option -gwv mode-keys)"
}
# The command when on ssh with latency. To make it work in this case too,
# sleep is added.
add_sleep_for_remote_shells() {
local pane_command
pane_command="$(tmux display-message -p '#{pane_current_command}')"
if [[ $pane_command =~ (ssh|mosh) ]]; then
sleep "$REMOTE_SHELL_WAIT_TIME"
fi
}
go_to_the_beginning_of_current_line() {
tmux send-key 'C-a'
if [ "$(shell_mode)" == "emacs" ]; then
tmux send-key 'C-a'
else
tmux send-key 'Escape' '0'
fi
}
enter_tmux_copy_mode() {
tmux copy-mode
tmux copy-mode
}
start_tmux_selection() {
if [ "$TMUX_COPY_MODE" == "vi" ]; then
# vi copy mode
tmux send-key 'Space'
else
# emacs copy mode
tmux send-key 'C-Space'
fi
if tmux_is_at_least 2.4; then
tmux send -X begin-selection
elif [ "$TMUX_COPY_MODE" == "vi" ]; then
# vi copy mode
tmux send-key 'Space'
else
# emacs copy mode
tmux send-key 'C-Space'
fi
}
# works when command spans accross multiple lines
end_of_line_in_copy_mode() {
if [ "$TMUX_COPY_MODE" == "vi" ]; then
# vi copy mode
# This sequence of keys consistently selects multiple lines
tmux send-key 'G' # go the the bottom of scrollback buffer
tmux send-key 'b' # beginning previous word
tmux send-key 'e' # end of next word
else
# emacs copy mode
tmux send-key 'C-e'
tmux send-key 'M-b'
tmux send-key 'M-f'
fi
if tmux_is_at_least 2.4; then
tmux send -X -N 150 'cursor-down' # 'down' key. 'vi' mode is faster so we're
# jumping more lines than emacs.
tmux send -X 'end-of-line' # End of line (just in case we are already at the last line).
tmux send -X 'previous-word' # Beginning of the previous word.
tmux send -X 'next-word-end' # End of next word.
elif [ "$TMUX_COPY_MODE" == "vi" ]; then
# vi copy mode
# This sequence of keys consistently selects multiple lines
tmux send-key '150' # Go to the bottom of scrollback buffer by using
tmux send-key 'j' # 'down' key. 'vi' mode is faster so we're
# jumping more lines than emacs.
tmux send-key '$' # End of line (just in case we are already at the last line).
tmux send-key 'b' # Beginning of the previous word.
tmux send-key 'e' # End of next word.
else
# emacs copy mode
for ((c = 1; c <= '30'; c++)); do # go to the bottom of scrollback buffer
tmux send-key 'C-n'
done
tmux send-key 'C-e'
tmux send-key 'M-b'
tmux send-key 'M-f'
fi
}
yank_to_clipboard() {
tmux send-key "$(yank_key)"
if tmux_is_at_least 2.4; then
# shellcheck disable=SC2119
tmux send -X copy-pipe-and-cancel "$(clipboard_copy_command)"
else
tmux send-key "$(yank_wo_newline_key)"
fi
}
go_to_the_end_of_current_line() {
tmux send-keys 'C-e'
}
display_notice() {
display_message 'Line copied to clipboard!'
if [ "$(shell_mode)" == "emacs" ]; then
tmux send-keys 'C-e'
else
tmux send-keys '$' 'a'
fi
}
yank_current_line() {
go_to_the_beginning_of_current_line
enter_tmux_copy_mode
start_tmux_selection
end_of_line_in_copy_mode
yank_to_clipboard
go_to_the_end_of_current_line
display_notice
go_to_the_beginning_of_current_line
add_sleep_for_remote_shells
enter_tmux_copy_mode
start_tmux_selection
end_of_line_in_copy_mode
yank_to_clipboard
go_to_the_end_of_current_line
display_message 'Line copied to clipboard!'
}
main() {
get_tmux_copy_mode
yank_current_line
get_tmux_copy_mode
yank_current_line
}
main

28
scripts/copy_pane_pwd.sh Executable file
View file

@ -0,0 +1,28 @@
#!/usr/bin/env bash
CURRENT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
HELPERS_DIR="$CURRENT_DIR"
# shellcheck source=scripts/helpers.sh
source "${HELPERS_DIR}/helpers.sh"
pane_current_path() {
tmux display -p -F "#{pane_current_path}"
}
display_notice() {
display_message 'PWD copied to clipboard!'
}
main() {
local copy_command
local payload
# shellcheck disable=SC2119
copy_command="$(clipboard_copy_command)"
payload="$(pane_current_path | tr -d '\n')"
# $copy_command below should not be quoted
echo "$payload" | $copy_command
tmux set-buffer "$payload"
display_notice
}
main

208
scripts/helpers.sh Normal file
View file

@ -0,0 +1,208 @@
#!bash
# shellcheck disable=SC2239
yank_line="y"
yank_line_option="@yank_line"
yank_pane_pwd="Y"
yank_pane_pwd_option="@yank_pane_pwd"
yank_default="y"
yank_option="@copy_mode_yank"
put_default="Y"
put_option="@copy_mode_put"
yank_put_default="M-y"
yank_put_option="@copy_mode_yank_put"
yank_wo_newline_default="!"
yank_wo_newline_option="@copy_mode_yank_wo_newline"
yank_selection_default="clipboard"
yank_selection_option="@yank_selection"
yank_selection_mouse_default="primary"
yank_selection_mouse_option="@yank_selection_mouse"
yank_with_mouse_default="on"
yank_with_mouse_option="@yank_with_mouse"
yank_action_default="copy-pipe-and-cancel"
yank_action_option="@yank_action"
shell_mode_default="emacs"
shell_mode_option="@shell_mode"
custom_copy_command_default=""
custom_copy_command_option="@custom_copy_command"
override_copy_command_default=""
override_copy_command_option="@override_copy_command"
# helper functions
get_tmux_option() {
local option="$1"
local default_value="$2"
local option_value
option_value=$(tmux show-option -gqv "$option")
if [ -z "$option_value" ]; then
echo "$default_value"
else
echo "$option_value"
fi
}
yank_line_key() {
get_tmux_option "$yank_line_option" "$yank_line"
}
yank_pane_pwd_key() {
get_tmux_option "$yank_pane_pwd_option" "$yank_pane_pwd"
}
yank_key() {
get_tmux_option "$yank_option" "$yank_default"
}
put_key() {
get_tmux_option "$put_option" "$put_default"
}
yank_put_key() {
get_tmux_option "$yank_put_option" "$yank_put_default"
}
yank_wo_newline_key() {
get_tmux_option "$yank_wo_newline_option" "$yank_wo_newline_default"
}
yank_selection() {
get_tmux_option "$yank_selection_option" "$yank_selection_default"
}
yank_selection_mouse() {
get_tmux_option "$yank_selection_mouse_option" "$yank_selection_mouse_default"
}
yank_with_mouse() {
get_tmux_option "$yank_with_mouse_option" "$yank_with_mouse_default"
}
yank_action() {
get_tmux_option "$yank_action_option" "$yank_action_default"
}
shell_mode() {
get_tmux_option "$shell_mode_option" "$shell_mode_default"
}
custom_copy_command() {
get_tmux_option "$custom_copy_command_option" "$custom_copy_command_default"
}
override_copy_command() {
get_tmux_option "$override_copy_command_option" "$override_copy_command_default"
}
# Ensures a message is displayed for 5 seconds in tmux prompt.
# Does not override the 'display-time' tmux option.
display_message() {
local message="$1"
# display_duration defaults to 5 seconds, if not passed as an argument
if [ "$#" -eq 2 ]; then
local display_duration="$2"
else
local display_duration="5000"
fi
# saves user-set 'display-time' option
local saved_display_time
saved_display_time=$(get_tmux_option "display-time" "750")
# sets message display time to 5 seconds
tmux set-option -gq display-time "$display_duration"
# displays message
tmux display-message "$message"
# restores original 'display-time' value
tmux set-option -gq display-time "$saved_display_time"
}
command_exists() {
local command="$1"
type "$command" >/dev/null 2>&1
}
clipboard_copy_command() {
local mouse="${1:-false}"
# installing reattach-to-user-namespace is recommended on OS X
if [ -n "$(override_copy_command)" ]; then
override_copy_command
elif command_exists "pbcopy"; then
if command_exists "reattach-to-user-namespace"; then
echo "reattach-to-user-namespace pbcopy"
else
echo "pbcopy"
fi
elif command_exists "clip.exe"; then # WSL clipboard command
echo "cat | clip.exe"
elif command_exists "wl-copy"; then # wl-clipboard: Wayland clipboard utilities
echo "wl-copy"
elif command_exists "xsel"; then
local xsel_selection
if [[ $mouse == "true" ]]; then
xsel_selection="$(yank_selection_mouse)"
else
xsel_selection="$(yank_selection)"
fi
echo "xsel -i --$xsel_selection"
elif command_exists "xclip"; then
local xclip_selection
if [[ $mouse == "true" ]]; then
xclip_selection="$(yank_selection_mouse)"
else
xclip_selection="$(yank_selection)"
fi
echo "xclip -selection $xclip_selection"
elif command_exists "putclip"; then # cygwin clipboard command
echo "putclip"
elif [ -n "$(custom_copy_command)" ]; then
custom_copy_command
fi
}
# Cache the TMUX version for speed.
tmux_version="$(tmux -V | cut -d ' ' -f 2 | sed 's/next-//')"
tmux_is_at_least() {
if [[ $tmux_version == "$1" ]] || [[ $tmux_version == master ]]; then
return 0
fi
local i
local -a current_version wanted_version
IFS='.' read -ra current_version <<<"$tmux_version"
IFS='.' read -ra wanted_version <<<"$1"
# fill empty fields in current_version with zeros
for ((i = ${#current_version[@]}; i < ${#wanted_version[@]}; i++)); do
current_version[i]=0
done
# fill empty fields in wanted_version with zeros
for ((i = ${#wanted_version[@]}; i < ${#current_version[@]}; i++)); do
wanted_version[i]=0
done
for ((i = 0; i < ${#current_version[@]}; i++)); do
if ((10#${current_version[i]} < 10#${wanted_version[i]})); then
return 1
fi
if ((10#${current_version[i]} > 10#${wanted_version[i]})); then
return 0
fi
done
return 0
}

View file

@ -1,64 +0,0 @@
yank_line="y"
yank_line_option="@yank_line"
yank_default="y"
yank_option="@copy_mode_yank"
put_default="C-y"
put_option="@copy_mode_put"
yank_put_default="M-y"
yank_put_option="@copy_mode_yank_put"
# helper functions
get_tmux_option() {
local option="$1"
local default_value="$2"
local option_value=$(tmux show-option -gqv "$option")
if [ -z "$option_value" ]; then
echo "$default_value"
else
echo "$option_value"
fi
}
yank_line_key() {
echo "$(get_tmux_option "$yank_line_option" "$yank_line")"
}
yank_key() {
echo "$(get_tmux_option "$yank_option" "$yank_default")"
}
put_key() {
echo "$(get_tmux_option "$put_option" "$put_default")"
}
yank_put_key() {
echo "$(get_tmux_option "$yank_put_option" "$yank_put_default")"
}
# Ensures a message is displayed for 5 seconds in tmux prompt.
# Does not override the 'display-time' tmux option.
display_message() {
local message="$1"
# display_duration defaults to 5 seconds, if not passed as an argument
if [ "$#" -eq 2 ]; then
local display_duration="$2"
else
local display_duration="5000"
fi
# saves user-set 'display-time' option
local saved_display_time=$(get_tmux_option "display-time" "750")
# sets message display time to 5 seconds
tmux set-option -gq display-time "$display_duration"
# displays message
tmux display-message "$message"
# restores original 'display-time' value
tmux set-option -gq display-time "$saved_display_time"
}

13
vagrant_provisioning.sh Normal file
View file

@ -0,0 +1,13 @@
#!/usr/bin/env bash
sudo apt-get update
sudo apt-get install -y git-core expect vim xclip
sudo apt-get install -y python-software-properties software-properties-common
# install latest Tmux 1.9a
sudo add-apt-repository -y ppa:pi-rho/dev
sudo apt-get update
sudo apt-get install -y tmux=1.9a-1~ppa1~p
# configure X11 for xclip testing
echo "export DISPLAY='IP:0.0'" >>/home/vagrant/.bashrc

7
video/README.md Normal file
View file

@ -0,0 +1,7 @@
## Tmux yank screencast
This directory contains docs used for creating
[tmux yank screencast](https://vimeo.com/102039099).
- `script.md` - this file contains a script and a voiceover used to produce the
screencast

BIN
video/screencast_img.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 52 KiB

204
video/script.md Normal file
View file

@ -0,0 +1,204 @@
# Tmux yank screencast script
1 - Intro - what's the plugin about
===================================
Actions
-------
- none, just clear screen
Script
------
In this screencast we'll demo a tmux yank plugin.
This plugin enables you to copy some text from tmux to the system clipboard,
along with some extra functionality we'll show.
It was made to complement tmux copycat plugin which we'll also be using for
selection in this screencast.
2 - problems with vanilla tmux and `y`
==============================
Actions
-------
- $ echo 'example url https://github.com/tmux-plugins/tmux-yank'
- highlight url
- enter
- paste url
- remove url
- highlight url again
- 'y'
- paste with cmd + v
Script
------
Let's show a problem scenario you might be having with tmux.
I'll generate some example output with a url in the terminal.
Okay, now I want to copy that url and open it in the browser.
By using tmux copycat saved search I'll quickly select the url.
I'll press enter, a "bajnding" for copy.
I can now paste it in tmux by pressing prefix + right angle bracket.
That works, but there's a problem. Tmux paste works only within tmux. Pressing
prefix + right angle bracket won't work in the browser where I actually want the
above url to be.
Ideally, when I copy some text in tmux, I want it to be available for paste
anywhere on the system with control-v or command-v if I'm on a Mac.
Enter tmux-yank which enables just that.
I'll select the url again.
Tmux-yank provides a convenient "bajnding" so that pressing 'y' in copy mode
copies the text and makes it available in system clipboard.
I'm on a mac so I'll press command-v and there you have you have it.
It goes without saying that this paste will work in the browser.
Personally, I use tmux-yank copying all the time so I don't have to think in
terms of being in tmux versus working with the rest of the system.
And also, this way I can avoid tmux default paste binding 'prefix + right angle
bracket' because it is a bit clunky and unintuitive.
3 - showing 'ctrl-y'
====================
Actions
-------
- git status -sb (file1.txt, file2.txt, file3.txt)
- git add
- highlight last file
- y
- paste and enter to git add a file
- clear screen
- git status -sb
- git add
- highlight last file
- ctrl-y and git add a file
- cmd - v
Script
------
Let's show another feature.
I'll invoke git status command for the project I'm in.
Now I want to git add only the last file.
I'll select the last file, yank and paste.
Do you think we can optimize this?
Often with tmux there's a need to copy a selection, and paste it to the command
line immediately.
Tmux-yank provides a so called 'put selection' command. Let's demo it.
I'll highlight another git status file and press control-y.
The selection is immediately 'put' to the command line. That's one step, instead
of two.
A nice side-effect of 'put selection' command is that it preserves the system
clipboard content.
If I press command-v now you'll see that the clipboard still contains the
previous entry. 'put selection' command didn't overwrite it.
4. show 'line yank'
===================
Actions
-------
- clear pane scrollback
- split window
- echo 'some command'
- ctrl-p to show the last command
- prefix + y
- go the the pane on the right
- cmd - v
Script
------
The last tmux-yank feature I'd like to show is 'line yank'.
It enables you to quickly copy the current command line to system clipoard.
The nice thing is, it also works for commands that strech multiple lines.
But here's the basic example. I'll write a simple command.
Okay, that works. Now, I want to execute that same command in the pane on the
right. I could of course type the command again, but that's tedious and I could
make a typo.
Another solution is mouse selection, but that's just slow and lame.
I'll use the 'line yank' feature.
I'll press prefix + 'y' and the command is copied. Notice there were no changes
to the command itself - it is intact.
In the second pane on the right I can paste the line with command - v.
5. show 'line yank' with the production server
==============================================
Actions
-------
- left pane - local psql console
- right pane - psql console on developsta
- prepared create_table command on the left
- execute the command, it's ok
- show the command again
- show that mouse selection is innefective
- prefix + y
- switch to right pane
- paste
- enter
Script
------
One scenario where I find line yank feature really useful is when I have to
execute a command on the production server.
Here I have the local environment in the left pane, and I'm connected to
the production server in the right pane.
The task I want to perform is creating a database table on the
production server.
Frankly, I feel hesitatnt to type that command straight on production.
I'd rather first try and debug it locally, and then execute it on production.
Let's do that then. I'll open a database console locally and type the command.
Oh, it looks like I have a typo. It's good I tried this locally first.
Ok, the command works and is now ready. How do I now run in on production?
Typing this again, with the possibility of making a typo is not an option.
Let's try mouse selection.
Hm, that won't work either. It seems I can't scope mouse
selection to the left pane.
Let's now try line yank with prefix + 'y'.
Notice we're copying a multi-line command.
I'll paste it in the right pane.
That looks ok, so I'll execute it.. and it's good.
6. Outro
========
Actions
-------
- just a blank screen
Script
------
That's it for this screencast. I hope you'll find tmux-yank useful.

110
yank.tmux
View file

@ -1,60 +1,92 @@
#!/usr/bin/env bash
CURRENT_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
CURRENT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
SCRIPTS_DIR="${CURRENT_DIR}/scripts"
HELPERS_DIR="${CURRENT_DIR}/scripts"
source "$CURRENT_DIR/scripts/key_binding_helpers.sh"
# shellcheck source=scripts/helpers.sh
source "${HELPERS_DIR}/helpers.sh"
command_exists() {
local command="$1"
type "$command" >/dev/null 2>&1
}
clipboard_copy_command() {
if command_exists "xclip"; then
echo "xclip"
# reattach-to-user-namespace is required for OS X
elif command_exists "pbcopy" && command_exists "reattach-to-user-namespace"; then
echo "reattach-to-user-namespace pbcopy"
fi
clipboard_copy_without_newline_command() {
local copy_command="$1"
printf "tr -d '\\n' | %s" "$copy_command"
}
set_error_bindings() {
local key_bindings="$(yank_key) $(put_key) $(yank_put_key)"
local key
for key in $key_bindings; do
tmux bind-key -t vi-copy "$key" copy-pipe "$CURRENT_DIR/scripts/tmux_yank_error_message.sh"
tmux bind-key -t emacs-copy "$key" copy-pipe "$CURRENT_DIR/scripts/tmux_yank_error_message.sh"
done
local key_bindings key
key_bindings="$(yank_key) $(put_key) $(yank_put_key)"
for key in $key_bindings; do
if tmux_is_at_least 2.4; then
tmux bind-key -T copy-mode-vi "$key" send-keys -X copy-pipe-and-cancel "tmux display-message 'Error! tmux-yank dependencies not installed!'"
tmux bind-key -T copy-mode "$key" send-keys -X copy-pipe-and-cancel "tmux display-message 'Error! tmux-yank dependencies not installed!'"
else
tmux bind-key -t vi-copy "$key" copy-pipe "tmux display-message 'Error! tmux-yank dependencies not installed!'"
tmux bind-key -t emacs-copy "$key" copy-pipe "tmux display-message 'Error! tmux-yank dependencies not installed!'"
fi
done
}
error_handling_if_command_not_present() {
local copy_command="$1"
if [ -z "$copy_command" ]; then
set_error_bindings
exit 0
fi
local copy_command="$1"
if [ -z "$copy_command" ]; then
set_error_bindings
exit 0
fi
}
# `yank_without_newline` binding isn't intended to be used by the user. It is
# a helper for `copy_line` command.
set_copy_mode_bindings() {
local copy_command="$1"
tmux bind-key -t vi-copy "$(yank_key)" copy-pipe "$copy_command"
tmux bind-key -t vi-copy "$(put_key)" copy-pipe "tmux paste-buffer"
tmux bind-key -t vi-copy "$(yank_put_key)" copy-pipe "$copy_command; tmux paste-buffer"
local copy_command="$1"
local copy_wo_newline_command
copy_wo_newline_command="$(clipboard_copy_without_newline_command "$copy_command")"
local copy_command_mouse
copy_command_mouse="$(clipboard_copy_command "true")"
if tmux_is_at_least 2.4; then
tmux bind-key -T copy-mode-vi "$(yank_key)" send-keys -X "$(yank_action)" "$copy_command"
tmux bind-key -T copy-mode-vi "$(put_key)" send-keys -X copy-pipe-and-cancel "tmux paste-buffer -p"
tmux bind-key -T copy-mode-vi "$(yank_put_key)" send-keys -X copy-pipe-and-cancel "$copy_command; tmux paste-buffer -p"
tmux bind-key -T copy-mode-vi "$(yank_wo_newline_key)" send-keys -X "$(yank_action)" "$copy_wo_newline_command"
if [[ "$(yank_with_mouse)" == "on" ]]; then
tmux bind-key -T copy-mode-vi MouseDragEnd1Pane send-keys -X "$(yank_action)" "$copy_command_mouse"
fi
tmux bind-key -t emacs-copy "$(yank_key)" copy-pipe "$copy_command"
tmux bind-key -t emacs-copy "$(put_key)" copy-pipe "tmux paste-buffer"
tmux bind-key -t emacs-copy "$(yank_put_key)" copy-pipe "$copy_command; tmux paste-buffer"
tmux bind-key -T copy-mode "$(yank_key)" send-keys -X "$(yank_action)" "$copy_command"
tmux bind-key -T copy-mode "$(put_key)" send-keys -X copy-pipe-and-cancel "tmux paste-buffer -p"
tmux bind-key -T copy-mode "$(yank_put_key)" send-keys -X copy-pipe-and-cancel "$copy_command; tmux paste-buffer -p"
tmux bind-key -T copy-mode "$(yank_wo_newline_key)" send-keys -X "$(yank_action)" "$copy_wo_newline_command"
if [[ "$(yank_with_mouse)" == "on" ]]; then
tmux bind-key -T copy-mode MouseDragEnd1Pane send-keys -X "$(yank_action)" "$copy_command_mouse"
fi
else
tmux bind-key -t vi-copy "$(yank_key)" copy-pipe "$copy_command"
tmux bind-key -t vi-copy "$(put_key)" copy-pipe "tmux paste-buffer -p"
tmux bind-key -t vi-copy "$(yank_put_key)" copy-pipe "$copy_command; tmux paste-buffer -p"
tmux bind-key -t vi-copy "$(yank_wo_newline_key)" copy-pipe "$copy_wo_newline_command"
if [[ "$(yank_with_mouse)" == "on" ]]; then
tmux bind-key -t vi-copy MouseDragEnd1Pane copy-pipe "$copy_command_mouse"
fi
tmux bind-key -t emacs-copy "$(yank_key)" copy-pipe "$copy_command"
tmux bind-key -t emacs-copy "$(put_key)" copy-pipe "tmux paste-buffer -p"
tmux bind-key -t emacs-copy "$(yank_put_key)" copy-pipe "$copy_command; tmux paste-buffer -p"
tmux bind-key -t emacs-copy "$(yank_wo_newline_key)" copy-pipe "$copy_wo_newline_command"
if [[ "$(yank_with_mouse)" == "on" ]]; then
tmux bind-key -t emacs-copy MouseDragEnd1Pane copy-pipe "$copy_command_mouse"
fi
fi
}
set_copy_line_bindings() {
local copy_command="$1"
tmux bind-key "$(yank_line_key)" run-shell "$CURRENT_DIR/scripts/copy_line.sh $copy_command"
set_normal_bindings() {
tmux bind-key "$(yank_line_key)" run-shell -b "$SCRIPTS_DIR/copy_line.sh"
tmux bind-key "$(yank_pane_pwd_key)" run-shell -b "$SCRIPTS_DIR/copy_pane_pwd.sh"
}
main() {
local copy_command="$(clipboard_copy_command)"
error_handling_if_command_not_present "$copy_command"
set_copy_mode_bindings "$copy_command"
set_copy_line_bindings "$copy_command"
local copy_command
copy_command="$(clipboard_copy_command)"
error_handling_if_command_not_present "$copy_command"
set_copy_mode_bindings "$copy_command"
set_normal_bindings
}
main