diff --git a/modules/clipboard/README.md b/modules/clipboard/README.md new file mode 100644 index 00000000..ef988d7a --- /dev/null +++ b/modules/clipboard/README.md @@ -0,0 +1,9 @@ +Clipboard +========= + +Integrates zsh clipboard with system clipboard. + +Settings +-------- + +Make sure to set IS_MAC_OS correctly in init.zsh. diff --git a/modules/clipboard/init.zsh b/modules/clipboard/init.zsh new file mode 100644 index 00000000..bbd8fdf3 --- /dev/null +++ b/modules/clipboard/init.zsh @@ -0,0 +1,62 @@ +# +# Integrates the zsh clipboard with the system clipboard. +# +# Authors: +# Nir Friedman +# + +# If running Mac OS, set this to 1 +local IS_MAC_OS=0 + +if [[ IS_MAC_OS -eq 0 ]]; then + function cutbuffer() { + zle .$WIDGET + echo $CUTBUFFER | xclip -selection clipboard + } +else + function cutbuffer() { + zle .$WIDGET + echo $CUTBUFFER | pbcopy + } +fi + +zle_cut_widgets=( + vi-backward-delete-char + vi-change + vi-change-eol + vi-change-whole-line + vi-delete + vi-delete-char + vi-kill-eol + vi-substitute + vi-yank + vi-yank-eol +) + +for widget in $zle_cut_widgets +do + zle -N $widget cutbuffer +done + + +if [[ IS_MAC_OS -eq 0 ]]; then + function putbuffer() { + zle copy-region-as-kill "$(xclip -o -selection clipboard)" + zle .$WIDGET + } +else + function putbuffer() { + zle copy-region-as-kill "$(pbpaste)" + zle .$WIDGET + } +fi + +zle_put_widgets=( + vi-put-after + vi-put-before +) + +for widget in $zle_put_widgets +do + zle -N $widget putbuffer +done