Skip to content

Instantly share code, notes, and snippets.

@id
Last active August 29, 2015 14:00
Show Gist options
  • Save id/a6eefcadafb9ca9de5a4 to your computer and use it in GitHub Desktop.
Save id/a6eefcadafb9ca9de5a4 to your computer and use it in GitHub Desktop.
Share tmux buffer between hosts
# .tmux.conf:
bind-key -temacs-copy M-w copy-pipe "tmux_send_clip.sh"
# cat $HOME/bin/tmux_send_clip.sh:
#!/bin/sh
function maybe_show_err {
if [ $? -ne 0 ]
then
ERROR=$(</tmp/err)
tmux display-message "$? $ERROR"
fi
}
cat >/tmp/clip
cat /tmp/clip | ssh u@h1 "cat >/tmp/clip; tmux load-buffer /tmp/clip" 2> /tmp/err
maybe_show_err
cat /tmp/clip | ssh -o ConnectTimeout=1 -o ConnectionAttempts=1 u@h2 "cat | pbcopy" 2> /tmp/err
maybe_show_err
# cat $HOME/bin/emacs_share_buffer.sh
#!/bin/sh
tmux set-buffer "$1"
echo -n "$1" | tmux_send_clip.sh
# .emacs.d/init.el or .emacs
(defun my-cut-function (text &optional rest)
(let ((process-connection-type nil))
(start-process "emacs_share_buffer.sh" "*Messages*" "emacs_share_buffer.sh" text)))
(setq interprogram-cut-function 'my-cut-function)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment