diff --git a/modules/clipboard/README.md b/modules/clipboard/README.md index ef988d7a..08a124dd 100644 --- a/modules/clipboard/README.md +++ b/modules/clipboard/README.md @@ -3,7 +3,4 @@ Clipboard Integrates zsh clipboard with system clipboard. -Settings --------- - -Make sure to set IS_MAC_OS correctly in init.zsh. +On OSX, uses pbcopy and pbpaste. On cygwin, uses /dev/clipboard. On linux, requires either xclip or xsel be installed. diff --git a/modules/clipboard/init.zsh b/modules/clipboard/init.zsh index bbd8fdf3..b15ed76c 100644 --- a/modules/clipboard/init.zsh +++ b/modules/clipboard/init.zsh @@ -5,20 +5,18 @@ # 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 +function cutbuffer { + zle .$WIDGET + if [[ "$OSTYPE" == darwin* ]]; then echo $CUTBUFFER | pbcopy - } -fi + elif [[ "$OSTYPE" == cygwin* ]]; then + echo $CUTBUFFER | tee > /dev/clipboard + elif (( $+commands[xclip] )); then + echo $CUTBUFFER | xclip -selection clipboard + elif (( $+commands[xsel] )); then + echo $CUTBUFFER | xsel --clipboard --input + fi +} zle_cut_widgets=( vi-backward-delete-char @@ -33,30 +31,28 @@ zle_cut_widgets=( vi-yank-eol ) -for widget in $zle_cut_widgets -do +for widget in $zle_cut_widgets; do zle -N $widget cutbuffer done - -if [[ IS_MAC_OS -eq 0 ]]; then - function putbuffer() { +function putbuffer { + if [[ "$OSTYPE" == darwin* ]]; then + zle copy-region-as-kill "$(pbcopy)" + elif [[ "$OSTYPE" == cygwin* ]]; then + zle copy-region-as-kill "$(cat /dev/clipboard)" + elif (( $+commands[xclip] )); then zle copy-region-as-kill "$(xclip -o -selection clipboard)" - zle .$WIDGET - } -else - function putbuffer() { - zle copy-region-as-kill "$(pbpaste)" - zle .$WIDGET - } -fi + elif (( $+commands[xsel] )); then + zle copy-region-as-kill "$(xsel --clipboard --output)" + fi + zle .$WIDGET +} zle_put_widgets=( vi-put-after vi-put-before ) -for widget in $zle_put_widgets -do +for widget in $zle_put_widgets; do zle -N $widget putbuffer done