From 5d5a506f35417c8c71900003c1d7400af5099b9b Mon Sep 17 00:00:00 2001 From: Tom Willemse Date: Fri, 21 Oct 2016 14:51:21 +0200 Subject: [PATCH] Allow zsh to copy/paste to clipboard --- zsh/.zsh/functions/x-copy-region-as-kill | 3 +++ zsh/.zsh/functions/x-kill-region | 3 +++ zsh/.zsh/functions/x-yank | 3 +++ zsh/zshrc.org | 16 ++++++++++++++++ 4 files changed, 25 insertions(+) create mode 100644 zsh/.zsh/functions/x-copy-region-as-kill create mode 100644 zsh/.zsh/functions/x-kill-region create mode 100644 zsh/.zsh/functions/x-yank diff --git a/zsh/.zsh/functions/x-copy-region-as-kill b/zsh/.zsh/functions/x-copy-region-as-kill new file mode 100644 index 0000000..b032362 --- /dev/null +++ b/zsh/.zsh/functions/x-copy-region-as-kill @@ -0,0 +1,3 @@ +# -*- mode: sh; -*- +zle copy-region-as-kill +print -rn $CUTBUFFER | xsel -bi diff --git a/zsh/.zsh/functions/x-kill-region b/zsh/.zsh/functions/x-kill-region new file mode 100644 index 0000000..725ac72 --- /dev/null +++ b/zsh/.zsh/functions/x-kill-region @@ -0,0 +1,3 @@ +# -*- mode: sh; -*- +zle kill-region +print -rn $CUTBUFFER | xsel -bi diff --git a/zsh/.zsh/functions/x-yank b/zsh/.zsh/functions/x-yank new file mode 100644 index 0000000..72dd264 --- /dev/null +++ b/zsh/.zsh/functions/x-yank @@ -0,0 +1,3 @@ +# -*- mode: sh; -*- +CUTBUFFER=$(xsel -bo < /dev/null) +zle yank diff --git a/zsh/zshrc.org b/zsh/zshrc.org index 66550ee..2207ead 100644 --- a/zsh/zshrc.org +++ b/zsh/zshrc.org @@ -56,6 +56,22 @@ Load all plugins. zplug load --verbose #+END_SRC +Make some widgets for interacting with the clipboard. + +#+BEGIN_SRC sh + zle -N x-copy-region-as-kill + zle -N x-kill-region + zle -N x-yank +#+END_SRC + +Bind them to keyboard shortcuts. + +#+BEGIN_SRC sh + bindkey -e '^[w' x-copy-region-as-kill + bindkey -e '^W' x-kill-region + bindkey -e '^Y' x-yank +#+END_SRC + Initialize completion. This triggers loading of zsh-syntax-highlighting as well.