From ed6f1078ff38e2f614fe3dd5b1d8566ebfb574ea Mon Sep 17 00:00:00 2001 From: Ole Tange Date: Fri, 9 Jun 2023 18:09:10 +0200 Subject: [PATCH] clipboard: Copy to/from X clipboard. --- Makefile | 21 +++++---- clipboard/clipboard | 109 ++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 120 insertions(+), 10 deletions(-) create mode 100755 clipboard/clipboard diff --git a/Makefile b/Makefile index bf07b99..62b6a24 100644 --- a/Makefile +++ b/Makefile @@ -1,15 +1,16 @@ -CMD = 2grep 2search blink burncpu bwlimit drac duplicate-packets em \ - emoticons encdir fanspeed field find-first-fail find-optimal \ - forever fxkill G gitnext gitundo goodpasswd histogram Loffice \ - mtrr mirrorpdf neno not off pdfman pidcmd pidtree plotpipe \ - puniq ramusage rand rclean rina rn rrm seekmaniac shython \ - sound-reload splitvideo stdout swapout T teetime timestamp \ - tracefile transpose upsidedown vid w4it-for-port-open \ - whitehash wifi-reload wssh youtube-lbry ytv yyyymmdd +CMD = 2grep 2search blink burncpu bwlimit clipboard drac \ + duplicate-packets em emoticons encdir fanspeed field \ + find-first-fail find-optimal forever fxkill G gitnext gitundo \ + goodpasswd histogram Loffice mtrr mirrorpdf neno not off \ + pdfman pidcmd pidtree plotpipe puniq ramusage rand rclean \ + rina rn rrm seekmaniac shython sound-reload splitvideo stdout \ + swapout T teetime timestamp tracefile transpose upsidedown \ + vid w4it-for-port-open whitehash wifi-reload wssh \ + youtube-lbry ytv yyyymmdd all: 2search/2grep.1 2search/2search.1 blink/blink.1 \ - burncpu/burncpu.1 bwlimit/bwlimit.1 drac/drac.1 \ - encdir/encdir.1 fanspeed/fanspeed.1 field/field.1 \ + burncpu/burncpu.1 bwlimit/bwlimit.1 clipboard/clipboard.1 \ + drac/drac.1 encdir/encdir.1 fanspeed/fanspeed.1 field/field.1 \ find-first-fail/find-first-fail.1 find-optimal/find-optimal.1 \ G/G.1 gitnext/gitnext.1 gitundo/gitundo.1 \ goodpasswd/goodpasswd.1 histogram/histogram.1 \ diff --git a/clipboard/clipboard b/clipboard/clipboard new file mode 100755 index 0000000..4ccf7e2 --- /dev/null +++ b/clipboard/clipboard @@ -0,0 +1,109 @@ +#!/bin/bash + +: <<=cut +=encoding utf8 + +=head1 NAME + +clipboard - copy to or from X clipboard + + +=head1 SYNOPSIS + +B + + +=head1 DESCRIPTION + +B can be used in 3 ways. + +=head2 End of a pipe - save to clipboard + +If placed last in a pipe B will take standard output from a +command and save it to the clipboard. + +Equivalent to: B + +=head3 Example + + cat file | clipboard + +=head2 Start of a pipe - paste the clipboard + +If placed first in a pipe B will paste content of the +clipboard to standard output. + +Equivalent to: B + +=head3 Example + + clipboard | cat + +=head2 In the middle of a pipe - save and paste + +If placed in the middle of a pipe B will copy standard +output from a command and copy it to the clipboard and pass on the +standard output. + +Equivalent to: B + +=head3 Example + + cat | clipboard | cat + + +=head1 AUTHOR + +Copyright (C) 2023 Ole Tange, +http://ole.tange.dk and Free Software Foundation, Inc. + + +=head1 LICENSE + +Copyright (C) 2012 Free Software Foundation, Inc. + +This program is free software; you can redistribute it and/or modify +it under the terms of the GNU General Public License as published by +the Free Software Foundation; either version 3 of the License, or +at your option any later version. + +This program is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +GNU General Public License for more details. + +You should have received a copy of the GNU General Public License +along with this program. If not, see . + + +=head1 SEE ALSO + +B(1), B(1), B(1) + + +=cut + + +#debug_log=/tmp/T-debug +debug_log=/dev/null + +if tty -s ; then + # STDIN is terminal + # Don't care what STDOUT is + # clipboard | cat => paste clipboard + # clipboard => paste clipboard + echo xsel -o -b >> $debug_log + xsel -o -b +else + if [ -t 1 ] ; then + # STDOUT = terminal + # cat | clipboard => copy to clipboard + echo xsel -i -b >> $debug_log + xsel -i -b + else + # STDOUT redir'ed + # cat | clipboard | cat => copy and forward clipboard + echo xsel tee >> $debug_log + tee >(xsel -i -b) + fi +fi