pipe commands into clipboard

I often need to pipe commands into the clipboard. E.g when I type “pwd” to get the present working directory, I would normally select the line and then copy it into my clipboard.

After a while this became tedious so I wrote a script to make life easier. I created a bash script called “toclip”…

and now I can call it like this:

pwd | toclip

This is my little bash script, I hope it helps:


#!/bin/sh
#Suggested name: toclip
read a #read Standard in.
INPUT_IS=${a}
echo $*$a "sent to clipboard"  #we actually use both stdin and aguments passed in.
echo -n "$*${a}" | xclip      #-n removes newline feeds at the end
echo -n "$*${a}" | xclip -selection c

 

Leave a comment