1
0
mirror of https://github.com/seejohnrun/haste-client.git synced 2025-12-17 17:21:29 +00:00

11 Commits

Author SHA1 Message Date
John Crepezzi
ca0c9b239f Bump version 2012-04-22 22:38:20 -04:00
John Crepezzi
5d88f11605 Remove () 2012-04-22 22:38:06 -04:00
John Crepezzi
859de525b1 Merge pull request #6 from jokull/master
`HASTE_SERVER` variable should be `dup`ed
2012-04-22 19:37:30 -07:00
Jökull Sólberg Auðunsson
75ddd39187 Remove runtime error handler, dup environment string. 2012-04-21 16:56:30 +00:00
John Crepezzi
b24842ac6f Bump version to 0.1.1 2012-01-28 10:10:39 -05:00
John Crepezzi
636eec2924 Change how the pathname is received in haste-client 2012-01-28 10:10:23 -05:00
John Crepezzi
cf4c274d67 Added a note on WinHaste to the README 2012-01-27 09:44:43 -05:00
John Crepezzi
f2c6260bd0 Bump version to 0.1.0 2012-01-14 22:19:12 -05:00
John Crepezzi
457520d107 Filepath cleanup 2012-01-14 22:18:53 -05:00
John Crepezzi
9e7b8e86ae Merge pull request #1 from phaza/master
Ability to give a filename as first argument to haste client
2012-01-14 18:28:46 -08:00
Peter Haza
ca02796551 Ability to give a file as first argument to haste-client
This patch makes it possible to either pipe data into the haste client,
or just give a filename as first argument.

Signed-off-by: Peter Haza
2011-11-29 20:28:30 +01:00
4 changed files with 32 additions and 11 deletions

View File

@@ -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:
@@ -23,6 +33,10 @@ alias work_haste="HASTE_SERVER=http://something.com haste"
After which you can use `work_haste` to send hastes to that server instead. 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.
## Author ## Author
John Crepezzi <john.crepezzi@gmail.com> John Crepezzi <john.crepezzi@gmail.com>

View File

@@ -1,6 +1,8 @@
#!/usr/bin/env ruby #!/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 = Haste::CLI.new
cli.start cli.start

View File

@@ -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,25 +25,25 @@ 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 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
def server def server
return @server if @server return @server if @server
@server = ENV['HASTE_SERVER'] || Haste::DEFAULT_URL @server = ENV['HASTE_SERVER'].dup || Haste::DEFAULT_URL
@server.chop! if server.end_with?('/') @server.chop! if server.end_with?('/')
@server @server
end end

View File

@@ -1,5 +1,5 @@
module Haste module Haste
VERSION = '0.0.5' VERSION = '0.1.2'
end end