gist: 1035 Download_button fork
public
Public Clone URL: git://gist.github.com/1035.git
gistie
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
#!/usr/bin/env ruby
# Made by Pieter de Bie <frimmirf@gmail.com>
# Based on a "Pastie" task by someone
 
require "tempfile"
 
GIST_URL = 'http://gist.github.com/gists'
 
if ARGV.include? "-p"
  text = `pbpaste`
elsif !ARGV.empty?
  @filename = ARGV.shift
  text = File.read(File.expand_path(@filename))
elsif ENV["FILE"]
  @filename = ENV["FILE"]
  text = File.read(File.expand_path(ENV["FILE"]))
else
  text = STDIN.read
end
 
@filename ||= "Unnamed File"
@extension = File.extname(@filename)
@extension = "txt" if @extension == ""
 
text_file = Tempfile.open('w+')
text_file << text
text_file.flush
 
cmd = <<-EOS
curl #{GIST_URL} \
-s -L -o /dev/null -w "%{url_effective}" \
-F "file_ext[gistfile1]=#{@extionson}" \
-F "file_name[gistfile1]=#{@filename}" \
-F "file_contents[gistfile1]=<#{text_file.path}" \
-F "x=27" \
-F "y=27"
EOS
 
url = %x{#{cmd}}
text_file.close(true)
 
`echo #{url} | pbcopy`
puts "Copied to pasteboard: #{url}"

Owner

pd

Fork Of

gist: 1032 by anonymous

Revisions

  • e197ae Tue Jul 22 07:36:44 -0700 2008