mirror of
https://github.com/seejohnrun/haste-client.git
synced 2025-12-17 01:01:28 +00:00
Compare commits
32 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
ea7750c3bb | ||
|
|
d380711d26 | ||
|
|
a195f017e2 | ||
|
|
4e3e90f7cc | ||
|
|
a7df62a0a5 | ||
|
|
ce764ca7c4 | ||
|
|
e6532aa100 | ||
|
|
82d191fc5e | ||
|
|
2ef8f926af | ||
|
|
6430635bfa | ||
|
|
028e7c4424 | ||
|
|
b10fa4782a | ||
|
|
d8c4be9744 | ||
|
|
7913dd521d | ||
|
|
25140d99f5 | ||
|
|
6760a64957 | ||
|
|
98e72bce43 | ||
|
|
b53350c723 | ||
|
|
be8d4bc5de | ||
|
|
42bad59634 | ||
|
|
e156c031a8 | ||
|
|
ca0c9b239f | ||
|
|
5d88f11605 | ||
|
|
859de525b1 | ||
|
|
75ddd39187 | ||
|
|
b24842ac6f | ||
|
|
636eec2924 | ||
|
|
cf4c274d67 | ||
|
|
f2c6260bd0 | ||
|
|
457520d107 | ||
|
|
9e7b8e86ae | ||
|
|
ca02796551 |
42
README.md
42
README.md
@@ -13,6 +13,30 @@ This can be really really cool in combination with `pbcopy`, like:
|
||||
|
||||
after which the contents of `file` will be accessible at a URL which has been copied to your pasteboard.
|
||||
|
||||
## Installation
|
||||
|
||||
``` bash
|
||||
gem install haste
|
||||
```
|
||||
|
||||
## Support
|
||||
|
||||
Please consider paying what you think haste-client is worth:
|
||||
|
||||
<a href="https://www.stripeme.com/pay/1r2f">
|
||||
<img alt="Pay" src="https://www.stripeme.com/pay.jpg" />
|
||||
</a>
|
||||
|
||||
## Making uploading file contents easier
|
||||
|
||||
If you supply a valid file path as argument #1 to the client, it will be uploaded:
|
||||
|
||||
``` bash
|
||||
# equivelant
|
||||
cat file | haste
|
||||
haste file
|
||||
```
|
||||
|
||||
## Changing the location of your haste server
|
||||
|
||||
By default, haste will point at `http://hastebin.com`. You can change this by setting the value of `ENV['HASTE_SERVER']` to the URL of your haste server. You can also use `alias` to make easy shortcuts if you commonly use a few hastes intermingled with each other. To do that, you'd put something like this into ~.bash_profile:
|
||||
@@ -23,6 +47,24 @@ alias work_haste="HASTE_SERVER=http://something.com haste"
|
||||
|
||||
After which you can use `work_haste` to send hastes to that server instead.
|
||||
|
||||
## Windows Support
|
||||
|
||||
If you'd like an alternative on Windows that supports functionality similar to `pbcopy`, check out Aidan Ryan's [WinHaste](https://github.com/ajryan/WinHaste) project.
|
||||
|
||||
## Lightweight Alternative
|
||||
|
||||
Han Boetes has contributed a simple shell-script alternative for those not interested in installing a RubyGem:
|
||||
|
||||
``` bash
|
||||
haste(){ ( echo "% $@"; eval "$@" ) | curl -F "$@=<-" http://hastebin.com/documents|awk -F '"' '{print "http://hastebin.com/"$4}'}
|
||||
```
|
||||
|
||||
Usage:
|
||||
|
||||
``` bash
|
||||
haste `cat index.html
|
||||
```
|
||||
|
||||
## Author
|
||||
|
||||
John Crepezzi <john.crepezzi@gmail.com>
|
||||
|
||||
16
Rakefile
16
Rakefile
@@ -1,7 +1,6 @@
|
||||
require 'rspec/core/rake_task'
|
||||
require File.dirname(__FILE__) + '/lib/haste/version'
|
||||
|
||||
task :build => :test do
|
||||
|
||||
task :build do
|
||||
system "gem build haste.gemspec"
|
||||
end
|
||||
|
||||
@@ -12,14 +11,3 @@ task :release => :build do
|
||||
# push the gem
|
||||
system "gem push haste-#{Haste::VERSION}.gem"
|
||||
end
|
||||
|
||||
RSpec::Core::RakeTask.new(:test) do |t|
|
||||
t.pattern = 'spec/**/*_spec.rb'
|
||||
fail_on_error = true # be explicit
|
||||
end
|
||||
|
||||
RSpec::Core::RakeTask.new(:rcov) do |t|
|
||||
t.pattern = 'spec/**/*_spec.rb'
|
||||
t.rcov = true
|
||||
fail_on_error = true # be explicit
|
||||
end
|
||||
|
||||
@@ -1,6 +1,8 @@
|
||||
#!/usr/bin/env ruby
|
||||
|
||||
require File.dirname(__FILE__) + '/../lib/haste'
|
||||
require 'pathname'
|
||||
path = Pathname.new(__FILE__)
|
||||
require File.expand_path(File.dirname(path.realpath) + '/../lib/haste')
|
||||
|
||||
cli = Haste::CLI.new
|
||||
cli.start
|
||||
|
||||
31
lib/haste.rb
31
lib/haste.rb
@@ -1,5 +1,6 @@
|
||||
require 'json'
|
||||
require 'net/http'
|
||||
require 'net/https'
|
||||
require 'uri'
|
||||
|
||||
module Haste
|
||||
@@ -8,37 +9,47 @@ module Haste
|
||||
|
||||
class CLI
|
||||
|
||||
attr_reader :input
|
||||
|
||||
# Pull all of the data from STDIN
|
||||
def initialize
|
||||
@input = STDIN.readlines.join
|
||||
@input.strip!
|
||||
if STDIN.tty?
|
||||
file = ARGV.first
|
||||
abort 'No input file given' unless file
|
||||
abort "#{file}: No such path" unless File.exists?(file)
|
||||
@input = open(file).read
|
||||
else
|
||||
@input = STDIN.readlines.join
|
||||
end
|
||||
# clean up
|
||||
@input.rstrip!
|
||||
end
|
||||
|
||||
# Upload the and output the URL we get back
|
||||
def start
|
||||
uri = URI.parse server
|
||||
http = Net::HTTP.new uri.host, uri.port
|
||||
response = http.post '/documents', input
|
||||
if uri.scheme =~ /^https/
|
||||
http.use_ssl = true
|
||||
http.verify_mode = OpenSSL::SSL::VERIFY_NONE
|
||||
end
|
||||
response = http.post '/documents', @input
|
||||
if response.is_a?(Net::HTTPOK)
|
||||
data = JSON.parse(response.body)
|
||||
method = STDOUT.tty? ? :puts : :print
|
||||
STDOUT.send method, "#{server}/#{data['key']}"
|
||||
else
|
||||
STDERR.puts "failure uploading: #{response.code}"
|
||||
abort "failure uploading: #{response.code}"
|
||||
end
|
||||
rescue RuntimeError, JSON::ParserError => e
|
||||
STDERR.puts "failure uploading: #{response.code}"
|
||||
rescue JSON::ParserError => e
|
||||
abort "failure parsing response: #{e.message}"
|
||||
rescue Errno::ECONNREFUSED => e
|
||||
STDERR.puts "failure connecting: #{e.message}"
|
||||
abort "failure connecting: #{e.message}"
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
def server
|
||||
return @server if @server
|
||||
@server = ENV['HASTE_SERVER'] || Haste::DEFAULT_URL
|
||||
@server = (ENV['HASTE_SERVER'] || Haste::DEFAULT_URL).dup
|
||||
@server.chop! if server.end_with?('/')
|
||||
@server
|
||||
end
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
module Haste
|
||||
|
||||
VERSION = '0.0.5'
|
||||
VERSION = '0.1.7'
|
||||
|
||||
end
|
||||
|
||||
Reference in New Issue
Block a user