find_gem 1.1.1 → 1.2.0

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.
data/History.txt CHANGED
@@ -1,3 +1,9 @@
1
+ == 1.2.0 2007-08-10
2
+
3
+ * "gem [command]" autocomplete supported too!! e.g. gem up[TAB] -> gem update
4
+ * Also "gem help [command]" autocomplete
5
+ * Reduced to one autocomplete script (for both local and remote)
6
+
1
7
  == 1.1.1 2007-08-10
2
8
 
3
9
  * Cleaned up the gem description, doh!
data/Manifest.txt CHANGED
@@ -6,12 +6,13 @@ Rakefile
6
6
  bin/edit_gem
7
7
  bin/find_gem
8
8
  bin/gem_autocomplete
9
- bin/gem_remote_autocomplete
10
9
  lib/find_gem.rb
10
+ lib/find_gem/gem_autocomplete.rb
11
11
  lib/find_gem/version.rb
12
12
  scripts/txt2html
13
13
  setup.rb
14
14
  test/test_find_gem.rb
15
+ test/test_gem_autocomplete.rb
15
16
  test/test_helper.rb
16
17
  website/index.html
17
18
  website/index.txt
data/README.txt CHANGED
@@ -34,7 +34,7 @@ To your ~/.bashrc or ~/.profile add
34
34
 
35
35
  complete -C gem_autocomplete -o default find_gem
36
36
  complete -C gem_autocomplete -o default edit_gem
37
- complete -C gem_remote_autocomplete -o default gem
37
+ complete -C gem_autocomplete -o default gem
38
38
 
39
39
  And reload your profile:
40
40
 
data/bin/gem_autocomplete CHANGED
@@ -2,15 +2,18 @@
2
2
 
3
3
  # To your ~/.bashrc add
4
4
  # complete -C gem_autocomplete -o default find_gem
5
+ # complete -C gem_autocomplete -o default edit_gem
6
+ # complete -C gem_autocomplete -o default gem
7
+ # The latter supports autocompletion of gem commands, and then gem names after the command name
5
8
 
6
- def gem_list_clean
7
- @list ||= `gem list | grep "^\\w" | sed -e "s/ .*//"`
9
+ begin
10
+ require 'rubygems'
11
+ rescue LoadError
12
+ # no rubygems to load, so we fail silently
8
13
  end
9
14
 
10
- after_match = $'
11
- gem_match = (after_match.empty? || after_match =~ /\s$/) ? nil : after_match.split.last
12
- gems = (gem_list_clean.split("\n")[1..-1] || [])
13
- gems = gems.select { |t| /^#{Regexp.escape gem_match}/ =~ t } if gem_match
15
+ require 'find_gem'
16
+ require 'find_gem/gem_autocomplete'
17
+ include FindGem
14
18
 
15
- puts gems
16
- exit 0
19
+ GemAutocomplete.new.run(ENV["COMP_LINE"])
@@ -0,0 +1,65 @@
1
+ module FindGem
2
+ class GemAutocomplete
3
+ attr_accessor :comp_line
4
+
5
+ def remote_cmds
6
+ ['gem install']
7
+ end
8
+
9
+ def local_cmds
10
+ @local_cmds ||= %w[find_gem edit_gem] + %w[contents dependency rdoc uninstall unpack update].map {|cmd| "gem #{cmd}"}
11
+ end
12
+
13
+ def gem_cmd
14
+ ['gem help', 'gem']
15
+ end
16
+
17
+ def cmds_re(cmds)
18
+ /^(#{cmds.join('|')})\b/
19
+ end
20
+
21
+ def list_clean(comp_line)
22
+ return gem_remote_list($') if cmds_re(remote_cmds) =~ comp_line
23
+ return gem_local_list($') if cmds_re(local_cmds) =~ comp_line
24
+ return gem_commands_list($') if cmds_re(gem_cmd) =~ comp_line
25
+ ""
26
+ end
27
+
28
+ def filter_by_after_match(list, after_match)
29
+ list.grep(/^#{Regexp.escape after_match.strip}/)
30
+ end
31
+
32
+ def gem_remote_list(after_match)
33
+ @remote_list ||= begin
34
+ list = `gem list --remote | grep "^\\w" | sed -e "s/ .*//"`
35
+ filter_by_after_match(list, after_match)
36
+ end
37
+ end
38
+
39
+ def gem_local_list(after_match)
40
+ @local_list ||= begin
41
+ list = `gem list | grep "^\\w" | sed -e "s/ .*//"`
42
+ filter_by_after_match(list, after_match)
43
+ end
44
+ end
45
+
46
+ def gem_commands_list(after_match)
47
+ @commands ||= begin
48
+ list = cmdline_gem_commands.split("\n").map { |line| line.split.first }
49
+ filter_by_after_match(list, after_match)
50
+ end
51
+ end
52
+
53
+ def cmdline_gem_commands
54
+ `gem help commands | grep "^ \\w"`
55
+ end
56
+
57
+ def match_gem_commands?
58
+ end
59
+
60
+ def run(comp_line, _exit = true)
61
+ puts self.list_clean(comp_line)
62
+ exit 0 if _exit
63
+ end
64
+ end
65
+ end
@@ -1,8 +1,8 @@
1
1
  module FindGem #:nodoc:
2
2
  module VERSION #:nodoc:
3
3
  MAJOR = 1
4
- MINOR = 1
5
- TINY = 1
4
+ MINOR = 2
5
+ TINY = 0
6
6
 
7
7
  STRING = [MAJOR, MINOR, TINY].join('.')
8
8
  end
@@ -0,0 +1,62 @@
1
+ require File.dirname(__FILE__) + '/test_helper.rb'
2
+ require File.join(File.dirname(__FILE__), '../lib/find_gem/gem_autocomplete')
3
+
4
+ class TestGemAutocomplete < Test::Unit::TestCase
5
+
6
+ def setup
7
+ @gem_ac = FindGem::GemAutocomplete.new
8
+ end
9
+
10
+ def test_gem_commands
11
+ @gem_ac.expects(:cmdline_gem_commands).returns(<<-EOS
12
+ install Install a gem into the local repository
13
+ pristine Restores gem directories to pristine condition from files
14
+ query Query gem information in local or remote repositories
15
+ search Display all gems whose name contains STRING
16
+ specification Display gem specification (in yaml)
17
+ uninstall Uninstall gems from the local repository
18
+ unpack Unpack an installed gem to the current directory
19
+ update Update the named gem (or all installed gems) in the local
20
+ EOS
21
+ )
22
+ expected = %w[install pristine query search specification uninstall unpack update]
23
+ commands = @gem_ac.gem_commands_list(" ")
24
+ assert_equal(expected, commands)
25
+ end
26
+
27
+ def test_trigger_gem_commands_autocomplete
28
+ @gem_ac.expects(:gem_commands_list).with(" ").returns(%w[install pristine query search specification uninstall unpack update])
29
+ comp_line = "gem "
30
+ @gem_ac.list_clean(comp_line)
31
+ end
32
+
33
+ def test_trigger_gem_commands_autocomplete_starting_with_un
34
+ @gem_ac.expects(:gem_commands_list).with(" un").returns(%w[uninstall unpack update])
35
+ comp_line = "gem un"
36
+ @gem_ac.list_clean(comp_line)
37
+ end
38
+
39
+ def test_trigger_gem_local_autocomplete
40
+ @gem_ac.expects(:gem_local_list).with(" ").returns(%w[active_record active_resource active_support rails])
41
+ comp_line = "gem uninstall "
42
+ @gem_ac.list_clean(comp_line)
43
+ end
44
+
45
+ def test_trigger_gem_local_autocomplete_starting_with_act
46
+ @gem_ac.expects(:gem_local_list).with(" act").returns(%w[active_record active_resource active_support])
47
+ comp_line = "gem uninstall act"
48
+ @gem_ac.list_clean(comp_line)
49
+ end
50
+
51
+ def test_trigger_gem_remote_autocomplete
52
+ @gem_ac.expects(:gem_remote_list).with(" ").returns(%w[active_record active_resource active_support rails])
53
+ comp_line = "gem install "
54
+ @gem_ac.list_clean(comp_line)
55
+ end
56
+
57
+ def test_trigger_gem_remote_autocomplete_starting_with_act
58
+ @gem_ac.expects(:gem_remote_list).with(" act").returns(%w[active_record active_resource active_support])
59
+ comp_line = "gem install act"
60
+ @gem_ac.list_clean(comp_line)
61
+ end
62
+ end
data/test/test_helper.rb CHANGED
@@ -1,2 +1,10 @@
1
1
  require 'test/unit'
2
2
  require File.dirname(__FILE__) + '/../lib/find_gem'
3
+
4
+ begin
5
+ require 'rubygems'
6
+ require 'mocha'
7
+ rescue LoadError
8
+ puts "Requires 'mocha' RubyGem to run tests"
9
+ exit 0
10
+ end
data/website/index.html CHANGED
@@ -33,7 +33,7 @@
33
33
  <h1>find_gem</h1>
34
34
  <div id="version" class="clickable" onclick='document.location = "http://rubyforge.org/projects/find_gem"; return false'>
35
35
  <p>Get Version</p>
36
- <a href="http://rubyforge.org/projects/find_gem" class="numbers">1.1.1</a>
36
+ <a href="http://rubyforge.org/projects/find_gem" class="numbers">1.2.0</a>
37
37
  </div>
38
38
  <h1>&#x2192; edit_gem name</h1>
39
39
 
@@ -112,7 +112,7 @@
112
112
  <pre>
113
113
  complete -C gem_autocomplete -o default find_gem
114
114
  complete -C gem_autocomplete -o default edit_gem
115
- complete -C gem_remote_autocomplete -o default gem
115
+ complete -C gem_autocomplete -o default gem
116
116
  </pre>
117
117
 
118
118
  <p>And reload your profile:</p>
data/website/index.txt CHANGED
@@ -52,7 +52,7 @@ To your ~/.bashrc or ~/.profile add
52
52
  <pre>
53
53
  complete -C gem_autocomplete -o default find_gem
54
54
  complete -C gem_autocomplete -o default edit_gem
55
- complete -C gem_remote_autocomplete -o default gem
55
+ complete -C gem_autocomplete -o default gem
56
56
  </pre>
57
57
 
58
58
  And reload your profile:
@@ -1,13 +1,13 @@
1
1
  body {
2
- background-color: #E1D1F1;
2
+ background-color: #4D2E67;
3
3
  font-family: "Georgia", sans-serif;
4
4
  font-size: 16px;
5
5
  line-height: 1.6em;
6
6
  padding: 1.6em 0 0 0;
7
- color: #333;
7
+ color: #eee;
8
8
  }
9
9
  h1, h2, h3, h4, h5, h6 {
10
- color: #444;
10
+ color: #A79712;
11
11
  }
12
12
  h1 {
13
13
  font-family: sans-serif;
@@ -16,28 +16,38 @@ h1 {
16
16
  line-height: 0.8em;
17
17
  letter-spacing: -0.1ex;
18
18
  margin: 5px;
19
+ color: #FFEDFA;
19
20
  }
21
+ h1.primary {
22
+ color: #A79712;
23
+ }
24
+
20
25
  li {
21
26
  padding: 0;
22
27
  margin: 0;
23
28
  list-style-type: square;
24
29
  }
25
30
  a {
26
- color: #5E5AFF;
27
- background-color: #DAC;
31
+ color: #A79712;
28
32
  font-weight: normal;
29
33
  text-decoration: underline;
30
34
  }
31
35
  blockquote {
32
36
  font-size: 90%;
33
37
  font-style: italic;
34
- border-left: 1px solid #111;
38
+ border-left: 1px solid #eee;
35
39
  padding-left: 1em;
36
40
  }
37
41
  .caps {
38
42
  font-size: 80%;
39
43
  }
40
44
 
45
+ strong {
46
+ background-color: #D09FDC;
47
+ color: #1B1B1A;
48
+ font-weight: normal;
49
+ }
50
+
41
51
  #main {
42
52
  width: 45em;
43
53
  padding: 0;
@@ -101,12 +111,12 @@ pre, code {
101
111
  text-align: right;
102
112
  font-family: sans-serif;
103
113
  font-weight: normal;
104
- background-color: #B3ABFF;
105
- color: #141331;
114
+ color: #FFEDFA;
115
+ background-color: #A79712;
106
116
  padding: 15px 20px 10px 20px;
107
117
  margin: 0 auto;
108
118
  margin-top: 15px;
109
- border: 3px solid #141331;
119
+ border: 3px solid #FFEDFA;
110
120
  }
111
121
 
112
122
  #version .numbers {
@@ -114,21 +124,11 @@ pre, code {
114
124
  font-size: 4em;
115
125
  line-height: 0.8em;
116
126
  letter-spacing: -0.1ex;
117
- margin-bottom: 15px;
118
- }
119
-
120
- #version p {
121
- text-decoration: none;
122
- color: #141331;
123
- background-color: #B3ABFF;
124
- margin: 0;
125
- padding: 0;
126
127
  }
127
128
 
128
129
  #version a {
129
130
  text-decoration: none;
130
- color: #141331;
131
- background-color: #B3ABFF;
131
+ color: #FFEDFA;
132
132
  }
133
133
 
134
134
  .clickable {
metadata CHANGED
@@ -3,8 +3,8 @@ rubygems_version: 0.9.4.3
3
3
  specification_version: 1
4
4
  name: find_gem
5
5
  version: !ruby/object:Gem::Version
6
- version: 1.1.1
7
- date: 2007-08-10 00:00:00 +02:00
6
+ version: 1.2.0
7
+ date: 2007-08-13 00:00:00 +02:00
8
8
  summary: bin/find_gem - returns the path to a RubyGem; bin/edit_gem - loads Gem source into editor. Supports auto-completion too!
9
9
  require_paths:
10
10
  - lib
@@ -37,12 +37,13 @@ files:
37
37
  - bin/edit_gem
38
38
  - bin/find_gem
39
39
  - bin/gem_autocomplete
40
- - bin/gem_remote_autocomplete
41
40
  - lib/find_gem.rb
41
+ - lib/find_gem/gem_autocomplete.rb
42
42
  - lib/find_gem/version.rb
43
43
  - scripts/txt2html
44
44
  - setup.rb
45
45
  - test/test_find_gem.rb
46
+ - test/test_gem_autocomplete.rb
46
47
  - test/test_helper.rb
47
48
  - website/index.html
48
49
  - website/index.txt
@@ -51,6 +52,7 @@ files:
51
52
  - website/template.rhtml
52
53
  test_files:
53
54
  - test/test_find_gem.rb
55
+ - test/test_gem_autocomplete.rb
54
56
  - test/test_helper.rb
55
57
  rdoc_options:
56
58
  - --main
@@ -65,7 +67,6 @@ executables:
65
67
  - edit_gem
66
68
  - find_gem
67
69
  - gem_autocomplete
68
- - gem_remote_autocomplete
69
70
  extensions: []
70
71
 
71
72
  requirements: []
@@ -1,18 +0,0 @@
1
- #!/usr/bin/env ruby
2
-
3
- # To your ~/.bashrc add
4
- # complete -C gem_remote_autocomplete -o default gem
5
-
6
- exit 0 unless /^(#{VALID_COMMANDS.join('|')})\b/ =~ ENV["COMP_LINE"]
7
-
8
- def gem_list_clean
9
- @list ||= `gem list --remote | grep "^\\w" | sed -e "s/ .*//"`
10
- end
11
-
12
- after_match = $'
13
- gem_match = (after_match.empty? || after_match =~ /\s$/) ? nil : after_match.split.last
14
- gems = (gem_list_clean.split("\n")[1..-1] || [])
15
- gems = gems.select { |t| /^#{Regexp.escape gem_match}/ =~ t } if gem_match
16
-
17
- puts gems
18
- exit 0