Christopher Bull bio photo

Christopher Bull

Aspiring Oceanographer at the British Antarctic Survey. Big data python enthusiast. Outdoor adventurer.

Email Twitter Github

Do you remember the moment when you realised in Linux that clicking the mouse wheel pasted selected text? I had a similar reveleation when I discovered xclip recently, a handy utility for pushing text into the clipboard. I’m forever copying and pasting paths from SSH sessions so here’s a bash function that does the work for you…

function clipit() #clipit path 
{
    if [[ ( $# -eq 0 ) || ( $1 == "--help" ) || ( $1 == "-h" ) ]] ; then
        echo "Usage: clipit FILENAME_PATHNAME" 
        echo "Purpose: gets full path of file or path and places in clipboard." 
        echo "       " 
        echo "Requires: xclip" 
        echo "       " 
        echo "Mandatory arguments: " 
        echo "FILENAME_PATHNAME: path to folder or file" 
        echo "       " 
        echo "Example." 
        echo "clipit filename.txt" 
        echo "       " 
        echo "becomes:       " 
        echo "readlink -e filename.txt|tr -d '\n'|xclip -selection c"

        return 1
    fi
  readlink -e ${1}|tr -d '\n'|xclip -selection c
}

If you’re got apt-get and sudo rights, then you can install xclip with:

sudo apt-get install xclip

If you don’t have either of the above, then you can compile from source with (defaults to the slow but likely available GNU compiler):

cd 
wget wget http://downloads.sourceforge.net/project/xclip/xclip/0.12/xclip-0.12.tar.gz
tar -xvf xclip-0.12.tar.gz
mv xclip-0.12 xclip
cd xclip
./configure --prefix=$HOME/xclip
make

Seems like a bit of work but it’s pretty quick. And then, once compiled, add the following to your ~/.bashrc…

#add xclip to the end of bash path
PATH=$PATH:~/xclip/

This assumes that you compiled in ~/xclip/ as above. Happy speedy copy/pasting!

In category: hpc