mirror of
https://github.com/seejohnrun/haste-client.git
synced 2025-12-17 09:11:29 +00:00
Compare commits
4 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
f2c6260bd0 | ||
|
|
457520d107 | ||
|
|
9e7b8e86ae | ||
|
|
ca02796551 |
10
README.md
10
README.md
@@ -13,6 +13,16 @@ 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.
|
after which the contents of `file` will be accessible at a URL which has been copied to your pasteboard.
|
||||||
|
|
||||||
|
## 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
|
## 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:
|
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:
|
||||||
|
|||||||
19
lib/haste.rb
19
lib/haste.rb
@@ -8,11 +8,16 @@ module Haste
|
|||||||
|
|
||||||
class CLI
|
class CLI
|
||||||
|
|
||||||
attr_reader :input
|
|
||||||
|
|
||||||
# Pull all of the data from STDIN
|
# Pull all of the data from STDIN
|
||||||
def initialize
|
def initialize
|
||||||
@input = STDIN.readlines.join
|
if STDIN.tty?
|
||||||
|
abort 'No input file given' unless ARGV.length == 1
|
||||||
|
abort "#{file}: No such path" unless File.exists?(file = ARGV[0])
|
||||||
|
@input = open(file).read
|
||||||
|
else
|
||||||
|
@input = STDIN.readlines.join
|
||||||
|
end
|
||||||
|
# clean up
|
||||||
@input.strip!
|
@input.strip!
|
||||||
end
|
end
|
||||||
|
|
||||||
@@ -20,18 +25,18 @@ module Haste
|
|||||||
def start
|
def start
|
||||||
uri = URI.parse server
|
uri = URI.parse server
|
||||||
http = Net::HTTP.new uri.host, uri.port
|
http = Net::HTTP.new uri.host, uri.port
|
||||||
response = http.post '/documents', input
|
response = http.post '/documents', @input
|
||||||
if response.is_a?(Net::HTTPOK)
|
if response.is_a?(Net::HTTPOK)
|
||||||
data = JSON.parse(response.body)
|
data = JSON.parse(response.body)
|
||||||
method = STDOUT.tty? ? :puts : :print
|
method = STDOUT.tty? ? :puts : :print
|
||||||
STDOUT.send method, "#{server}/#{data['key']}"
|
STDOUT.send method, "#{server}/#{data['key']}"
|
||||||
else
|
else
|
||||||
STDERR.puts "failure uploading: #{response.code}"
|
abort "failure uploading: #{response.code}"
|
||||||
end
|
end
|
||||||
rescue RuntimeError, JSON::ParserError => e
|
rescue RuntimeError, JSON::ParserError => e
|
||||||
STDERR.puts "failure uploading: #{response.code}"
|
abort "failure uploading: #{response.code}"
|
||||||
rescue Errno::ECONNREFUSED => e
|
rescue Errno::ECONNREFUSED => e
|
||||||
STDERR.puts "failure connecting: #{e.message}"
|
abort "failure connecting: #{e.message}"
|
||||||
end
|
end
|
||||||
|
|
||||||
private
|
private
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
module Haste
|
module Haste
|
||||||
|
|
||||||
VERSION = '0.0.5'
|
VERSION = '0.1.0'
|
||||||
|
|
||||||
end
|
end
|
||||||
|
|||||||
Reference in New Issue
Block a user