From e9ac61b7ad5eb354d2d5708c60ba682912fb17d8 Mon Sep 17 00:00:00 2001 From: Jonathan Hodgson Date: Wed, 4 Apr 2018 08:22:31 +0100 Subject: [PATCH] Make xclip work as I would expect --- config/oh-my-zsh/functions.zsh | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/config/oh-my-zsh/functions.zsh b/config/oh-my-zsh/functions.zsh index e2150356..5e0f72d2 100644 --- a/config/oh-my-zsh/functions.zsh +++ b/config/oh-my-zsh/functions.zsh @@ -6,6 +6,23 @@ function big-new-chromium () { chromium-snapshot-bin --force-device-scale-factor=$1 } +# make xclip work as I would expect. Copy to clipboard if piped data. Paste from otherwise +function xclip(){ +if command -v /usr/bin/xclip 1>/dev/null; then + if [[ -p /dev/stdin ]] ; then + # stdin is a pipe + # stdin -> clipboard + /usr/bin/xclip -i -selection clipboard + else + # stdin is not a pipe + # clipboard -> stdout + /usr/bin/xclip -o -selection clipboard + fi +else + echo "Remember to install xclip" +fi +} + #Swap two files function swap() { mv $1 $1._tmp;