bashy 0.0.2 → 0.1.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (5) hide show
  1. data/README.markdown +2 -0
  2. data/Rakefile +2 -2
  3. data/bin/bashy +8 -1
  4. data/lib/bashy.rb +39 -0
  5. metadata +6 -6
@@ -22,6 +22,8 @@ Using `bashy` from the command line is too simple:
22
22
  add: Adds a snippet. You must provide a name. You can provide a path
23
23
  to a file to import, but if ommited you can enter your snippet
24
24
  into the STDIN
25
+ pull: Adds a gist as a snippet. You must provide a URL and a name.
26
+ Make sure you use a valid GitHub Gist URL.
25
27
  list: Lists all added snippets.
26
28
  remove: Removes all snippets matching the names provided.
27
29
  run: Runs the given command, passing it any arguments given after
data/Rakefile CHANGED
@@ -11,7 +11,7 @@ require 'rake/testtask'
11
11
 
12
12
  spec = Gem::Specification.new do |s|
13
13
  s.name = 'bashy'
14
- s.version = '0.0.2'
14
+ s.version = '0.1.1'
15
15
  s.has_rdoc = true
16
16
  s.extra_rdoc_files = ['README.markdown', 'LICENSE']
17
17
  s.summary = 'A simple code snippet storage tool (whatever language you like), making it easy to save, run, and manage your scripts from the Terminal.'
@@ -24,7 +24,7 @@ spec = Gem::Specification.new do |s|
24
24
  s.bindir = "bin"
25
25
 
26
26
  # Adding the dependencies we need.
27
- s.add_dependency('highline', '>= 1.0')
27
+ s.add_dependency('highline', '~> 1.0')
28
28
  end
29
29
 
30
30
  Rake::GemPackageTask.new(spec) do |p|
data/bin/bashy CHANGED
@@ -32,10 +32,13 @@ begin
32
32
  when 'run'
33
33
  options[:name] = ARGV[1]
34
34
  options[:args] = ARGV[2..-1]
35
- when 'show', 'pull'
35
+ when 'show'
36
36
  options[:name] = ARGV[1]
37
37
  when 'remove'
38
38
  options[:names] = ARGV[1..-1]
39
+ when 'pull'
40
+ options[:url] = ARGV[1]
41
+ options[:name] = ARGV[2]
39
42
  end
40
43
 
41
44
  case options[:command]
@@ -53,6 +56,8 @@ begin
53
56
  Bashy::Run.new(options)
54
57
  when 'show'
55
58
  puts Bashy::Show.new(options).contents
59
+ when 'pull'
60
+ Bashy::Pull.new(options)
56
61
  end
57
62
  rescue Exception => e
58
63
  # Show help.
@@ -64,6 +69,8 @@ rescue Exception => e
64
69
  puts ' add: Adds a snippet. You must provide a name. You can provide a path'
65
70
  puts ' to a file to import, but if ommited you can enter your snippet'
66
71
  puts ' into the STDIN'
72
+ puts ' pull: Adds a gist as a snippet. You must provide a URL and a name.
73
+ Make sure you use a valid GitHub Gist URL.'
67
74
  puts ' list: Lists all added snippets.'
68
75
  puts ' remove: Removes all snippets matching the names provided.'
69
76
  puts ' run: Runs the given command, passing it any arguments given after'
@@ -1,6 +1,9 @@
1
1
  require 'fileutils'
2
2
  require 'etc'
3
3
  require 'yaml'
4
+ require 'net/http'
5
+ require 'uri'
6
+ require 'pp'
4
7
 
5
8
  module Bashy
6
9
  # Our folder where we'll be storing our snippets and config.
@@ -39,6 +42,7 @@ module Bashy
39
42
  end
40
43
 
41
44
  class ArgumentError < RuntimeError; end
45
+ class GistFetchError < RuntimeError; end
42
46
 
43
47
  class Clean
44
48
  def initialize(options = {})
@@ -122,6 +126,41 @@ module Bashy
122
126
  def initialize(options = {})
123
127
  # Check that our directories are in tact.
124
128
  Bashy::check_and_load_config_directory
129
+ # http://gist.github.com/547224
130
+ if(options[:url] =~ /http:\/\/gist\.github\.com\/([0-9]+)/)
131
+ id = options[:url].match(/http:\/\/gist\.github\.com\/([0-9]+)/)[1]
132
+ unless id.nil?
133
+ response = get_url('http://gist.github.com/api/v1/yaml/' + id)
134
+ if response && response.code == "200"
135
+ yaml = YAML::load(response.body)
136
+ filename = yaml['gists'][0][:files][0]
137
+
138
+ response = get_url('http://gist.github.com/raw/' + id + '/' + filename)
139
+ if response && response.code == "200"
140
+ options[:snippet] = response.body
141
+ else
142
+
143
+ end
144
+ Add.new(options)
145
+ else
146
+ raise(GistFetchError.new('The Gist you requested could not be fetched from GitHib successfully.'))
147
+ end
148
+ else
149
+ raise(ArgumentError)
150
+ end
151
+ else
152
+ raise(ArgumentError.new('Make sure you pass a valid URL to a GitHub gist.'))
153
+ end
154
+ end
155
+
156
+ private
157
+ def get_url(url)
158
+ url = URI.parse(url)
159
+ request = Net::HTTP::Get.new(url.path)
160
+ response = Net::HTTP.start(url.host, url.port) do |http|
161
+ http.request(request)
162
+ end
163
+ response
125
164
  end
126
165
  end
127
166
  end
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: bashy
3
3
  version: !ruby/object:Gem::Version
4
- hash: 27
4
+ hash: 25
5
5
  prerelease: false
6
6
  segments:
7
7
  - 0
8
- - 0
9
- - 2
10
- version: 0.0.2
8
+ - 1
9
+ - 1
10
+ version: 0.1.1
11
11
  platform: ruby
12
12
  authors:
13
13
  - Nathan Kleyn
@@ -15,7 +15,7 @@ autorequire:
15
15
  bindir: bin
16
16
  cert_chain: []
17
17
 
18
- date: 2010-08-17 00:00:00 +01:00
18
+ date: 2010-08-24 00:00:00 +01:00
19
19
  default_executable:
20
20
  dependencies:
21
21
  - !ruby/object:Gem::Dependency
@@ -24,7 +24,7 @@ dependencies:
24
24
  requirement: &id001 !ruby/object:Gem::Requirement
25
25
  none: false
26
26
  requirements:
27
- - - ">="
27
+ - - ~>
28
28
  - !ruby/object:Gem::Version
29
29
  hash: 15
30
30
  segments: