Created
August 24, 2011 20:18
-
-
Save tavisrudd/1169093 to your computer and use it in GitHub Desktop.
bash readline integration with clipboards: M-k = kill, M-y = yank, M-u = backwards kill
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
## derived from http://stackoverflow.com/questions/994563/integrate-readlines-kill-ring-and-the-x11-clipboard | |
## You need to choose which clipboard to integrate with, OS X or X11: | |
shell_copy() { | |
pbcopy # OS X | |
# or ssh user@remote_mac pbcopy | |
# or xclip | |
} | |
shell_yank() { | |
pbpaste | |
# or ssh user@remote_mac pbpaste | |
# or xclip -o | |
} | |
# in the above you could also copy and yank to gnu screen's paste buffer or even remote shared clipboards. | |
# Just pipe to wherever you want! | |
## then wire up readline | |
_xdiscard() { | |
echo -n "${READLINE_LINE:0:$READLINE_POINT}" | shell_copy | |
READLINE_LINE="${READLINE_LINE:$READLINE_POINT}" | |
READLINE_POINT=0 | |
} | |
_xkill() { | |
echo -n "${READLINE_LINE:$READLINE_POINT}" | shell_copy | |
READLINE_LINE="${READLINE_LINE:0:$READLINE_POINT}" | |
} | |
_xyank() { | |
CLIP=$(shell_yank) | |
COUNT=$(echo -n "$CLIP" | wc -c) | |
READLINE_LINE="${READLINE_LINE:0:$READLINE_POINT}${CLIP}${READLINE_LINE:$READLINE_POINT}" | |
READLINE_POINT=$(($READLINE_POINT + $COUNT)) | |
} | |
bind -m emacs -x '"\eu": _xdiscard' # backwards kill from point | |
bind -m emacs -x '"\ek": _xkill' | |
bind -m emacs -x '"\ey": _xyank' |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Hi Tavis,
I'm regularly ssh-ing between mac and linux machines, and I want to use these commands over ssh. How shell_copy and shell_yank would look like? Does the implementation depend on OS of the machine that I am: ssh-ing to or ssh-ing from? Or both?