Zsh copy & paste system wide for OS X, like in emacs
It's very annoying that i need to use mouse to copy text from the terminal.
Zsh provides nice emacs-like selection, although it uses its own kill-ring, and doesn't use system-wide clipboard. Oh-my-zsh doesn't help either.
So I wrote this code, to fix that. There are simple wrappers around default functions. Also there is a new behavior for ⌥-W
, which is more emacs like.
You can find gist here.
pb-kill-line () {
zle kill-line
echo -n $CUTBUFFER | pbcopy
}
pb-kill-whole-line () {
zle kill-whole-line
echo -n $CUTBUFFER | pbcopy
}
pb-backward-kill-word () {
zle backward-kill-word
echo -n $CUTBUFFER | pbcopy
}
pb-kill-word () {
zle kill-word
echo -n $CUTBUFFER | pbcopy
}
pb-kill-buffer () {
zle kill-buffer
echo -n $CUTBUFFER | pbcopy
}
pb-copy-region-as-kill-deactivate-mark () {
zle copy-region-as-kill
zle set-mark-command -n -1
echo -n $CUTBUFFER | pbcopy
}
pb-yank () {
CUTBUFFER=$(pbpaste)
zle yank
}
zle -N pb-kill-line
zle -N pb-kill-whole-line
zle -N pb-backward-kill-word
zle -N pb-kill-word
zle -N pb-kill-buffer
zle -N pb-copy-region-as-kill-deactivate-mark
zle -N pb-yank
bindkey '^K' pb-kill-line
bindkey '^U' pb-kill-whole-line
bindkey '\e^?' pb-backward-kill-word
bindkey '\e^H' pb-backward-kill-word
bindkey '^W' pb-backward-kill-word
bindkey '\ed' pb-kill-word
bindkey '\eD' pb-kill-word
bindkey '^X^K' pb-kill-buffer
bindkey '\ew' pb-copy-region-as-kill-deactivate-mark
bindkey '\eW' pb-copy-region-as-kill-deactivate-mark
bindkey '^Y' pb-yank
Written by Dmitry Yakimov
Related protips
Have a fresh tip? Share with Coderwall community!
Post
Post a tip
Best
#Zsh
Authors
Sponsored by #native_company# — Learn More
#native_title#
#native_desc#