From b694e9cdf5e6a357617ff52168ef496333283cec Mon Sep 17 00:00:00 2001 From: "Kenneth Benzie (Benie)" Date: Tue, 2 Mar 2021 20:04:33 +0000 Subject: [PATCH] Add copy and paste aliases to clipboard commands Interact with the clipboard through the `copy` and `paste` aliases. `copy` is defined when: 1. An `ssh` connection is detected, using OSC-52. 2. macOS is detected, using `pbcopy`. 3. `xsel` is detected. `paste` is define when: 1. macOS is detected, using `pbpaste`. 2. `xsel` is detected. --- utilities/utilities.plugin.zsh | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/utilities/utilities.plugin.zsh b/utilities/utilities.plugin.zsh index 946c3da..2806225 100644 --- a/utilities/utilities.plugin.zsh +++ b/utilities/utilities.plugin.zsh @@ -2,6 +2,25 @@ autoload colors && colors +# Abstract different ways to copy to the clipboard. +if [ -n "$SSH_CONNECTION" ] ; then + # Use OSC-52 to set the clipboard + alias copy='base64 | xargs -0 printf "\033]52;c;%s\a"' +elif [ "`uname`" = "Darwin" ]; then + # Use pbcopy to set the clipboard + alias copy='pbcopy' +elif which xclip &> /dev/null; then + # Use xclip to set the clipboard + alias copy='xclip -selection c' +fi + +# Abstract different ways to paste from the clipboard. +if [ "`uname`" = "Darwin" ]; then + alias paste='pbpaste' +elif which xclip &> /dev/null; then + alias paste='xclip -selection c -o' +fi + # Detect the type and extract an archive file. extract() { if [ -f $1 ]; then