19
Aug/08
8

Dumping to the Internets

I am constantly uploading files and pasting people URLs to said files hosted on some web server. After many years of typing the scp command and then manually transcribing the resulting URL, I finally made my life easier.

I shared it with some friends on IRC and everyone seemed to find it the most revolutionary script of 2008, so maybe it’s useful to the rest of the world.

In addition to printing the URL on the terminal, it also copies the URL into the primary X clipboard. This allows me to run the command upload foo and then quickly middle click the URL into IRC or a browser.

#!/bin/bash
user=username
host=host.org
[[ $# -lt 1 ]] && { echo "Not sure what to do..." 1>&2; exit 1; }
scp -r $* $user@$host:public_html && {
	URL="http://$host/~$user/$(basename $1)"
	echo "$URL"
	xselection -replace PRIMARY "$URL"
}

It assumes you have your ~/public_html directory on the server being shared over HTTP at /~username. In openSUSE 11.0, the xselection command is provided by, you guessed it, the xselection package.

Enjoy!

Comments (8) Trackbacks (0)
  1. David
    12:19 on August 19th, 2008

    This would make a great GNOME Do plugin.

  2. derfian
    12:58 on August 19th, 2008

    This reminds me of a script I wrote for nautilus some time ago which does just about the same thing. The xselection trick was new to me however, thanks for the hint! I used the notify-send utility to pop up a link once the file or directory was copied.

    I wrote more about it at http://e101.hamsterkollektivet.se/~derfian/2007/03/02/small-and-simple-tricks

  3. Aaron Bockover
    13:07 on August 19th, 2008

    @David: it would, but for me when I need to upload something, I’m already working in a terminal ;-)

    @derfian: Nice idea about notify-send. The xselection part of the script is really what makes this so useful to me.

  4. Barry Kelly
    15:19 on August 19th, 2008

    Watch out for those strange file names (spaces & dashes):

    scp -r — “$@” [...]

  5. Killerkiwi
    16:37 on August 19th, 2008

    I have some thing similar but for a nopaste site and imageshack I make it it an icon on the bar… I you click it it uploads the clipboard.. if you drop a text file on it uploads the content… if you drop an image it uploads the image

    Really handy stuff

  6. Aaron Bockover
    17:40 on August 19th, 2008

    @Barry: good point and good fix! Though I typically only care to share things I create and name, which I am known to do in a sane and consistent manner :-)

    @Killerkiwi: nice! That sounds useful.

  7. Staz
    19:27 on August 20th, 2008

    Nice tips about the xselection command.

    @Killerkiwi : would you mind sharing your script, it sounds really useful.

  8. Rick Harding
    17:07 on August 26th, 2008

    Thanks for this post. It makes so much sense. I’m always ftp’ing files up to share screenshots, recordmydesktop files, etc.

    I tend to upload to a couple of hosts based on if this is for work or public so I started a python project to handle some more use cases.
    https://launchpad.net/sendoff

    It’s a lot more overhead, but now that I’ve got it I’m already mad I didn’t do this a long time ago.

Leave a comment

No trackbacks yet.