A little Strongspace bash-fu

Last week Brett Terpstra came up with a simple bash function to push any file to your Public space and give back a TinyURL to that file on your clipboard. I cleaned it up a bit and thought it worthy of its own post.

Paste this function into an open Terminal window or add it to the end of /.profile. Make sure to substitute your_username with your Strongspace username.

function sshare () {
  scp "$1" ss:/strongspace/your_username/public
  url="https://www.strongspace.com/your_username/public/$1"
  tiny=$(curl -s --data-urlencode "url=$url" http://tinyurl.com/api-create.php)
  echo -n $tiny | pbcopy && echo $tiny
}

This function assumes you have a ssh alias named “ss” setup, but it’s not required. It also is more convenient with password-less ssh authentication.

Now run sshare some_filename to push and host any file off to Strongspace, e.g.

sshare "Ray LaMontagne - Beg Steal or Borrow.mp3"

  • http://brettterpstra.com Brett Terpstra

    Beautiful cleanup job :). I do think the echo $tiny deserves a -n, though, to clear that newline off the copy…

    • http://www.expandrive.com Jeff Mancuso

      Done

  • jrk

    Tweaked with Brett’s fix and support for paths/to/subdirectories via basename:

    function sshare () { scp "$1" ss:/strongspace/jrk/public url="https://www.strongspace.com/jrk/public/$(basename $1)" tiny=$(curl -s --data-urlencode "url=$url" http://tinyurl.com/api-create.php) echo -n $tiny | pbcopy && echo $tiny }

  • http://caudygeg.tumblr.com Craig Morgan

    Love this approach, I happen to prefer bit.ly (or now j.mp) for my shortening as it offers some tracking of clicks and allows me to record each shortened URL to my account. The only downside being that using their v3 API obviously requires an ID and authentication.

    Anyway, for a bit.ly version of the shortener replace the shortener line like so:

    tiny=$(curl -s --data-urlencode "longUrl=$url" --data-urlencode "login=XXXXX" --data-urlencode "apiKey=XXXXX" --data-urlencode "format=txt" http://api.bit.ly/v3/shorten)

    Where your login and apiKey values can be retrieved from bit.ly after login via the http://bit.ly/a/your_api_key url (bit.ly accounts are free, so if you want a new account signup at http://bit.ly/a/sign_up first!).

    To subsequently see click-thru info on the URL that is generated, add a + to the end of the shortened URL.

    HTH

    Craig