Mercurial > dotfiles
annotate unixSoft/bin/afcopy @ 480:4c5814d3cfd8
afcopy: some enhancements from Bryan's dotfiles
This makes `afcopy` able to drop things in the clipboard over ssh. Wild stuff.
See
https://bitbucket.org/bcmills/dotfiles/src/101956eeb90160f1d225ae23c8e6566c9df91c5c/bin/clip?at=default&fileviewer=file-view-default
for some details.
author | Augie Fackler <raf@durin42.com> |
---|---|
date | Thu, 14 Mar 2019 10:38:49 -0400 |
parents | b5178986dcbb |
children |
rev | line source |
---|---|
409
b5178986dcbb
af{copy,paste}: scripts so I can copy/paste with pipes across platforms
Augie Fackler <raf@durin42.com>
parents:
diff
changeset
|
1 #!/bin/sh |
b5178986dcbb
af{copy,paste}: scripts so I can copy/paste with pipes across platforms
Augie Fackler <raf@durin42.com>
parents:
diff
changeset
|
2 if [ `uname` = Darwin ] ; then |
b5178986dcbb
af{copy,paste}: scripts so I can copy/paste with pipes across platforms
Augie Fackler <raf@durin42.com>
parents:
diff
changeset
|
3 pbcopy |
b5178986dcbb
af{copy,paste}: scripts so I can copy/paste with pipes across platforms
Augie Fackler <raf@durin42.com>
parents:
diff
changeset
|
4 else |
480
4c5814d3cfd8
afcopy: some enhancements from Bryan's dotfiles
Augie Fackler <raf@durin42.com>
parents:
409
diff
changeset
|
5 if [ -z "${TMUX:-}" ]; then |
4c5814d3cfd8
afcopy: some enhancements from Bryan's dotfiles
Augie Fackler <raf@durin42.com>
parents:
409
diff
changeset
|
6 DATA="$(cat)" |
4c5814d3cfd8
afcopy: some enhancements from Bryan's dotfiles
Augie Fackler <raf@durin42.com>
parents:
409
diff
changeset
|
7 # Copy the data to the terminal clipboard using OSC 52 escape codes. |
4c5814d3cfd8
afcopy: some enhancements from Bryan's dotfiles
Augie Fackler <raf@durin42.com>
parents:
409
diff
changeset
|
8 # See http://invisible-island.net/xterm/ctlseqs/ctlseqs.html, “Ps = 5 2”. |
4c5814d3cfd8
afcopy: some enhancements from Bryan's dotfiles
Augie Fackler <raf@durin42.com>
parents:
409
diff
changeset
|
9 echo -en '\e]52;c;' |
4c5814d3cfd8
afcopy: some enhancements from Bryan's dotfiles
Augie Fackler <raf@durin42.com>
parents:
409
diff
changeset
|
10 echo -n "$DATA" | base64 -w0 |
4c5814d3cfd8
afcopy: some enhancements from Bryan's dotfiles
Augie Fackler <raf@durin42.com>
parents:
409
diff
changeset
|
11 echo -en '\a' |
4c5814d3cfd8
afcopy: some enhancements from Bryan's dotfiles
Augie Fackler <raf@durin42.com>
parents:
409
diff
changeset
|
12 else |
4c5814d3cfd8
afcopy: some enhancements from Bryan's dotfiles
Augie Fackler <raf@durin42.com>
parents:
409
diff
changeset
|
13 tmux set-buffer -- "$DATA" |
4c5814d3cfd8
afcopy: some enhancements from Bryan's dotfiles
Augie Fackler <raf@durin42.com>
parents:
409
diff
changeset
|
14 # Use a double-escape to send escape codes directly to the terminal. |
4c5814d3cfd8
afcopy: some enhancements from Bryan's dotfiles
Augie Fackler <raf@durin42.com>
parents:
409
diff
changeset
|
15 # See https://github.com/tmux/tmux/commit/79e30daeae1d49a1cf1dc4618edf1ec82804a80c. |
4c5814d3cfd8
afcopy: some enhancements from Bryan's dotfiles
Augie Fackler <raf@durin42.com>
parents:
409
diff
changeset
|
16 echo -en '\ePtmux;\e\e]52;c;' |
4c5814d3cfd8
afcopy: some enhancements from Bryan's dotfiles
Augie Fackler <raf@durin42.com>
parents:
409
diff
changeset
|
17 echo -n "$DATA" | base64 -w0 |
4c5814d3cfd8
afcopy: some enhancements from Bryan's dotfiles
Augie Fackler <raf@durin42.com>
parents:
409
diff
changeset
|
18 echo -en '\a\e\\' |
4c5814d3cfd8
afcopy: some enhancements from Bryan's dotfiles
Augie Fackler <raf@durin42.com>
parents:
409
diff
changeset
|
19 fi |
4c5814d3cfd8
afcopy: some enhancements from Bryan's dotfiles
Augie Fackler <raf@durin42.com>
parents:
409
diff
changeset
|
20 if [ -n "${DISPLAY:-}" ] ; then |
4c5814d3cfd8
afcopy: some enhancements from Bryan's dotfiles
Augie Fackler <raf@durin42.com>
parents:
409
diff
changeset
|
21 xclip -selection clipboard |
4c5814d3cfd8
afcopy: some enhancements from Bryan's dotfiles
Augie Fackler <raf@durin42.com>
parents:
409
diff
changeset
|
22 fi |
409
b5178986dcbb
af{copy,paste}: scripts so I can copy/paste with pipes across platforms
Augie Fackler <raf@durin42.com>
parents:
diff
changeset
|
23 fi |