Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP

Loading…

Copy on more than just OS X #8

Closed
wants to merge 1 commit into from

2 participants

@aashay

Hey look github fixed that forking issue. Hoorj!

Anyways here's that cloudapp hack I mentioned a month ago at the SF GitHub drinkup (at the Lookout). You probably don't remember me. Oh well, hope you're doing okay!

Feel free to decline the pull request, just wanted to show ya.

I actually never tested this on Winderz or OS X actually, only Linux. Hmm.

@holman
Owner

I'm conflicted on this. (Completely unrelated to you... this looks great.)

  • cloudapp has really gotten around. Bunch of people use her (and she was recently added to oh-my-zsh). I was thinking about adding it to the actual cloudapp ruby wrapper and just using it that way so we can test it and give it more "official" support.
  • The copy stuff seems to come up in a lot of things I write... I might extract that into, like, bin/copy or something (which will handle OS-independent copying).

Let me ruminate on this for a bit and come back to it.

@aashay
@holman
Owner

Yup, definitely was I've been thinking about. There's a few others that have gotten pulled out (like gifme that I'd like to promote somehow in my dotfiles, too, since they're pretty big to my workflow).

@holman
Owner

I think I just got a genius idea. Or a completely silly one. It's my favorite combination.

Hopefully I'll have time to hack it up this weekend... stay tuned. :)

@aashay
@partkyle partkyle referenced this pull request from a commit in partkyle/dotfiles
@ervandew ervandew fix restoring of mapping when rhs has no args to escape
fixes #8
2f432d1
@holman holman closed this
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Commits on Jul 19, 2011
  1. @aashay
This page is out of date. Refresh to see the latest.
Showing with 52 additions and 6 deletions.
  1. +52 −6 bin/cloudapp
View
58 bin/cloudapp 100755 → 100644
@@ -1,10 +1,10 @@
#!/usr/bin/env ruby
#
# cloudapp
-# Zach Holman / @holman
+# Hacked together with duct tape, hopes, and dreams by Aashay Desai / @aashay
+# Original by Zach Holman / @holman
#
-# Uploads a file from the command line to CloudApp, drops it into your
-# clipboard (on a Mac, at least).
+# Uploads a file from the command line to CloudApp, drops it into your clipboard
#
# Example:
#
@@ -46,15 +46,61 @@ if ARGV[0].nil?
puts "You need to specify a file to upload."
exit!(1)
end
+
+class Copier
+ class << self
+ # Public: tests if currently running on darwin.
+ #
+ # Returns true if running on darwin (MacOS X), else false
+ def darwin?
+ !!(RUBY_PLATFORM =~ /darwin/)
+ end
+
+ # Public: tests if currently running on windows.
+ #
+ # Apparently Windows RUBY_PLATFORM can be 'win32' or 'mingw32'
+ #
+ # Returns true if running on windows (win32/mingw32), else false
+ def windows?
+ !!(RUBY_PLATFORM =~ /win|mingw/)
+ end
+
+ # Public: returns the command used to copy a url to the
+ # clipboard for the current platform.
+ #
+ # Returns a String with the bin
+ def copy_command
+ if darwin?
+ 'pbcopy'
+ elsif windows?
+ 'clip'
+ else
+ 'xclip -selection clipboard'
+ end
+ end
+
+ # Public: copies a given url to the clipboard.
+ # This _should_ work in any POSIX environment and also windows,
+ # since they both have echo commands. I think. Maybe? I dunno.
+ #
+ # Returns nothing.
+ def copy(url)
+ system("echo #{url} | #{copy_command}")
+ end
+ end
+end
+
+puts "Connecting to CloudApp..."
CloudApp.authenticate(email,password)
url = CloudApp::Item.create(:upload, {:file => ARGV[0]}).url
# Say it for good measure.
-puts "Uploaded to #{url}."
+puts "Uploaded to #{url}..."
# Get the embed link.
url = "#{url}/#{ARGV[0].split('/').last}"
-# Copy it to your (Mac's) clipboard.
-`echo '#{url}' | tr -d "\n" | pbcopy`
+# Copy it to your clipboard.
+Copier::copy(url)
+puts "Copied #{url} to clipboard! ENJOY!"
Something went wrong with that request. Please try again.