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!

This entry was posted in uncategorized. Bookmark the permalink.

8 Responses to Dumping to the Internets

  1. David says:

    This would make a great GNOME Do plugin.

  2. derfian says:

    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. @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 says:

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

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

  5. Killerkiwi says:

    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. @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 says:

    Nice tips about the xselection command.

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

  8. Rick Harding says:

    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 Reply

Your email address will not be published. Required fields are marked *

*

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>