From 64db1f9723b7b68788db8696283e414b0034581a Mon Sep 17 00:00:00 2001 From: Nir Friedman Date: Sat, 24 Oct 2015 15:46:24 -0400 Subject: [PATCH] Add clipboard module --- modules/clipboard/README.md | 9 ++++++ modules/clipboard/init.zsh | 62 +++++++++++++++++++++++++++++++++++++ 2 files changed, 71 insertions(+) create mode 100644 modules/clipboard/README.md create mode 100644 modules/clipboard/init.zsh 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