godo 1.0.1 → 1.0.2

Sign up to get free protection for your applications and to get access to all the features.
data.tar.gz.sig CHANGED
Binary file
@@ -5,7 +5,7 @@ Rakefile
5
5
  bin/godo
6
6
  lib/godo.rb
7
7
  lib/finder.rb
8
- lib/iterm.rb
9
8
  lib/project.rb
10
9
  lib/session.rb
11
10
  lib/template.yml
11
+ lib/sessions/iterm_session.rb
data/README.txt CHANGED
@@ -1,28 +1,40 @@
1
1
  = godo
2
2
 
3
- * http://rubymatt.rubyforge.org/godo
3
+ * http://simplyruby.rubyforge.org/godo
4
4
 
5
5
  == DESCRIPTION:
6
6
 
7
7
  go (to project) do (stuffs)
8
8
 
9
- godo provides a smart way of opening a project folder and invoking a set of commands appropriate to
10
- that project. Examples might be starting mongrel, tailing one or more logs, starting consoles or IRB,
11
- opening empty terminal sessions, or making ssh connections.
9
+ godo provides a smart way of opening a project folder in multiple terminal tabs and, in each tab,
10
+ invoking a commands appropriate to that project. For example if the folder contains a Rails project
11
+ the actions might include: starting mongrel, tailing one or more logs, starting consoles or IRB
12
+ sessions, tailing production logs, opening an editor, running autospec, or gitk.
12
13
 
13
- godo works by searching your project paths for a search string and attempting to find the project you
14
- are talking about. It makes some straightforward efforts to disambiguate.
14
+ godo works by searching your project paths for a given search string and trying to match it against
15
+ paths found in one or more configured project roots. It will make some straightforward efforts to
16
+ disambiguate among multiple matches to find the one you want.
15
17
 
16
- godo then uses heuristics (which can be overriden or extended) to figure out what type of project it is,
17
- for example a RoR project using RSpec and Subversion. It then invokes a series of action appropriate to
18
- that project type, each action in its own terminal session.
18
+ godo then uses configurable heuristics to figure out what type of project it is, for example "a RoR
19
+ project using RSpec and Subversion". From that it will invokes a series of action appropriate to the
20
+ type of project detected with each action being run, from the project folder, in its own terminal
21
+ session.
19
22
 
20
23
  godo is entirely configured by a YAML file (~/.godo) that contains project types, heuristics, actions,
21
- project paths, and a session controller.
24
+ project paths, and a session controller. A sample configuration file is provided that can be installed
25
+ using godo --install.
22
26
 
23
- godo comes with an iTerm session controller that uses the rb-appscript gem to control iTerm. It should
24
- be straightforward to add a controller for Leopard Terminal or a controller that works in a different way
25
- (e.g. creating new windows instead of new tabs).
27
+ godo comes with an iTerm session controller for MacOSX that uses the rb-appscript gem to control iTerm
28
+ (see lib/session.rb and lib/sessions/iterm_session.rb). It should be relatively straightforward to add
29
+ new controller (e.g. for Leopard Terminal.app), or a controller that works in a different way (e.g. by
30
+ creating new windows instead of new tabs). There is nothing MacOSX specific about the rest of godo so
31
+ creating controllers for other unixen should be straightforward if they can be controlled from ruby.
32
+
33
+ godo is a rewrite of my original 'gp' script (http://matt.blogs.it/entries/00002674.html) which fixes
34
+ a number of the deficiencies of that script, turns it into a gem, has a better name, and steals the
35
+ idea of using heuristics to detect project types from Solomon Whites gp variant (http://onrails.org/articles/2007/11/28/scripting-the-leopard-terminal).
36
+
37
+ godo lives at the excellent GitHub: http://github.com/mmower/godo/ and accepts patches.
26
38
 
27
39
  == FEATURES/PROBLEMS:
28
40
 
@@ -32,9 +44,19 @@ be straightforward to add a controller for Leopard Terminal or a controller that
32
44
 
33
45
  == SYNOPSIS:
34
46
 
35
- godo project-search-string
47
+ To install the default configuration (will not overwrite an existing configuration file)
48
+
49
+ godo --install
50
+
51
+ To open a project with it's actions
36
52
 
37
- To override the project type use -o <matcher-name>
53
+ godo <project>
54
+
55
+ Where project is a search term that will match part of the project path name.
56
+
57
+ To open a project and override the project type (i.e. do not use heuristics):
58
+
59
+ godo -o <matcher> <project>
38
60
 
39
61
  == REQUIREMENTS:
40
62
 
data/Rakefile CHANGED
@@ -5,7 +5,7 @@ require 'hoe'
5
5
  require './lib/godo.rb'
6
6
 
7
7
  Hoe.new('godo', Godo::VERSION) do |p|
8
- p.rubyforge_name = 'rubymatt'
8
+ p.rubyforge_name = 'simplyruby'
9
9
  p.developer( 'Matt Mower', 'self@mattmower.com' )
10
10
  p.extra_deps << ['trollop','>= 1.7']
11
11
  p.extra_deps << ['rb-appscript','>= 0.5.1']
data/bin/godo CHANGED
@@ -20,7 +20,7 @@ if opts[:install]
20
20
  end
21
21
  else
22
22
  begin
23
- Godo.invoke( ARGV.shift, opts )
23
+ Godo.godo( ARGV.shift, opts )
24
24
  rescue Errno::ENOENT => e
25
25
  puts e.message
26
26
  puts "Use --install to create the default configuration file."
@@ -6,7 +6,18 @@ module Godo
6
6
 
7
7
  def self.find( query, options )
8
8
  finder = Finder.new( options["projects"], options["ignores"] )
9
- finder.find( Regexp.escape( query ) )
9
+ paths = finder.find( Regexp.escape( query ) )
10
+
11
+ if paths.size > 1
12
+ paths = strip_inexact_matches( query, paths )
13
+ if paths.size > 1
14
+ if base_match( paths )
15
+ paths[0,1]
16
+ end
17
+ end
18
+ end
19
+
20
+ paths
10
21
  end
11
22
 
12
23
  def initialize( roots, ignores )
@@ -45,6 +56,22 @@ module Godo
45
56
  ignore
46
57
  end
47
58
 
59
+ def strip_inexact_matches( query, paths )
60
+ # If any of the paths have the query as a complete path component
61
+ # then strip any paths that don't
62
+ if paths.any? { |path| path.split( File::SEPARATOR ).any? { |component| query == component } }
63
+ paths.select { |path| path.split( File::SEPARATOR ).any? { |component| query == component } }
64
+ else
65
+ paths
66
+ end
67
+ end
68
+
69
+ def base_match( paths )
70
+ # Is the first path a prefix for all subsequent-paths
71
+ path_match = Regexp.compile( "^#{paths.first}" )
72
+ paths[1..-1].all? { |path| path.match( path_match ) }
73
+ end
74
+
48
75
  end
49
76
 
50
77
  end
@@ -1,21 +1,28 @@
1
1
  require 'yaml'
2
2
 
3
3
  module Godo
4
- VERSION = '1.0.1'
4
+ VERSION = '1.0.2'
5
5
  LIBPATH = File.expand_path( File.dirname( __FILE__ ) )
6
6
 
7
+ # When called with no arguments this will return the path to the gem
8
+ # library for godo. Any arguments are then appended to the library
9
+ # path.
7
10
  def self.libpath( *args )
8
11
  args.empty? ? LIBPATH : File.join( LIBPATH, *args )
9
12
  end
10
13
 
14
+ # This method copies the template configuration file from the gem
15
+ # into the users home directory. It will raise an exception if the
16
+ # user already has a config file.
11
17
  def self.install_config
12
- raise "Will not overwrite config. Please delete ~/.godo if you wish to update it." if File.exists?( File.expand_path( '~/.godo' ) )
13
18
  self.copy( libpath( 'template.yml' ), '~/.godo' )
14
19
  end
15
-
20
+
21
+ # Copy a file handling overwrite protection.
16
22
  def self.copy( from, path, overwrite = false )
23
+ path = File.expand_path( path )
17
24
  if File.exists?( path ) && !overwrite
18
- raise "Cannot overwrite #{path}. Please delete first and try again."
25
+ raise "Will not overwrite #{path}. Please delete first and try again."
19
26
  else
20
27
  File.open( File.expand_path( path ), "w" ) do |file|
21
28
  file.write( File.read( from ) )
@@ -23,59 +30,25 @@ module Godo
23
30
  end
24
31
  end
25
32
 
26
- def self.invoke( query, options )
27
- Invoker.new( options ).invoke( query )
28
- end
29
-
30
- class Invoker
31
-
32
- def initialize( options )
33
- @options = options
34
- @config = YAML::load( File.read( File.expand_path( "~/.godo" ) ) )
35
- end
36
-
37
- def invoke( query )
38
- require 'finder'
39
- paths = Finder.find( query, @config )
40
- if paths.empty?
41
- puts "No match for: #{query}"
42
- else
43
- paths = strip_inexact_matches( query, paths )
44
- if paths.size > 1
45
- if base_match( paths )
46
- invoke_project( paths.first )
47
- else
48
- puts "Multiple ambgiuous matches for: #{query}"
49
- paths.each do |path|
50
- puts "\t#{path}"
51
- end
52
- end
53
- else
54
- invoke_project( paths.first )
55
- end
56
- end
57
- end
58
-
59
- def strip_inexact_matches( query, paths )
60
- # If any of the paths have the query as a complete path component
61
- # then strip any paths that don't
62
- if paths.any? { |path| path.split( File::SEPARATOR ).any? { |component| query == component } }
63
- paths.select { |path| path.split( File::SEPARATOR ).any? { |component| query == component } }
64
- else
65
- paths
33
+ # Given the query attempt to find a project path in any of the users configured
34
+ # project roots that matches. If a clear match is made detect the type of
35
+ # project and invoke the appropriate actions.
36
+ def self.godo( query, options )
37
+ config = YAML::load( File.read( File.expand_path( "~/.godo" ) ) )
38
+ require 'finder'
39
+ paths = Finder.find( query, config )
40
+ if paths.empty?
41
+ puts "No paths match for: #{query}"
42
+ elsif paths.size > 1
43
+ puts "Multiple, ambgiuous, paths match for: #{query}"
44
+ paths.each do |path|
45
+ puts "\t#{path}"
66
46
  end
67
- end
68
-
69
- def base_match( paths )
70
- # Is the first path a prefix for all subsequent-paths
71
- path_match = Regexp.compile( "^#{paths.first}" )
72
- paths[1..-1].all? { |path| path.match( path_match ) }
73
- end
74
-
75
- def invoke_project( path )
47
+ else
48
+ puts "Matching project: #{paths.first}"
76
49
  require 'project'
77
- project = Project.new( @options, @config )
78
- project.invoke( path )
50
+ project = Project.new( options, config )
51
+ project.invoke( paths.first )
79
52
  end
80
53
  end
81
54
 
@@ -1,3 +1,5 @@
1
+ require 'session'
2
+
1
3
  module Godo
2
4
 
3
5
  class Project
@@ -7,9 +9,7 @@ module Godo
7
9
  @heuristics = config["heuristics"]
8
10
  @actions = config["actions"]
9
11
  @matchers = config["matchers"]
10
-
11
- require config["sessions"].downcase
12
- @session_class = Godo.const_get( "#{config[ "sessions" ]}Session" )
12
+ @session_class = Godo.const_get( config["sessions"] )
13
13
  end
14
14
 
15
15
  def invoke( path )
@@ -52,4 +52,7 @@ module Godo
52
52
 
53
53
  end
54
54
 
55
+ # Load all Session subclasses in lib/sessions/*.rb
56
+ Dir.glob( "#{libpath('sessions')}/*.rb" ) { |path| require path }
57
+
55
58
  end
@@ -194,4 +194,4 @@ projects:
194
194
 
195
195
  # The session controller to use. Right now iTerm is the only
196
196
  # game in town.
197
- sessions: ITerm
197
+ sessions: ITermSession
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: godo
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.1
4
+ version: 1.0.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Matt Mower
@@ -60,7 +60,7 @@ dependencies:
60
60
  - !ruby/object:Gem::Version
61
61
  version: 1.5.1
62
62
  version:
63
- description: go (to project) do (stuffs) godo provides a smart way of opening a project folder and invoking a set of commands appropriate to that project. Examples might be starting mongrel, tailing one or more logs, starting consoles or IRB, opening empty terminal sessions, or making ssh connections. godo works by searching your project paths for a search string and attempting to find the project you are talking about. It makes some straightforward efforts to disambiguate. godo then uses heuristics (which can be overriden or extended) to figure out what type of project it is, for example a RoR project using RSpec and Subversion. It then invokes a series of action appropriate to that project type, each action in its own terminal session. godo is entirely configured by a YAML file (~/.godo) that contains project types, heuristics, actions, project paths, and a session controller. godo comes with an iTerm session controller that uses the rb-appscript gem to control iTerm. It should be straightforward to add a controller for Leopard Terminal or a controller that works in a different way (e.g. creating new windows instead of new tabs).
63
+ description: "go (to project) do (stuffs) godo provides a smart way of opening a project folder in multiple terminal tabs and, in each tab, invoking a commands appropriate to that project. For example if the folder contains a Rails project the actions might include: starting mongrel, tailing one or more logs, starting consoles or IRB sessions, tailing production logs, opening an editor, running autospec, or gitk. godo works by searching your project paths for a given search string and trying to match it against paths found in one or more configured project roots. It will make some straightforward efforts to disambiguate among multiple matches to find the one you want. godo then uses configurable heuristics to figure out what type of project it is, for example \"a RoR project using RSpec and Subversion\". From that it will invokes a series of action appropriate to the type of project detected with each action being run, from the project folder, in its own terminal session. godo is entirely configured by a YAML file (~/.godo) that contains project types, heuristics, actions, project paths, and a session controller. A sample configuration file is provided that can be installed using godo --install. godo comes with an iTerm session controller for MacOSX that uses the rb-appscript gem to control iTerm (see lib/session.rb and lib/sessions/iterm_session.rb). It should be relatively straightforward to add new controller (e.g. for Leopard Terminal.app), or a controller that works in a different way (e.g. by creating new windows instead of new tabs). There is nothing MacOSX specific about the rest of godo so creating controllers for other unixen should be straightforward if they can be controlled from ruby. godo is a rewrite of my original 'gp' script (http://matt.blogs.it/entries/00002674.html) which fixes a number of the deficiencies of that script, turns it into a gem, has a better name, and steals the idea of using heuristics to detect project types from Solomon Whites gp variant (http://onrails.org/articles/2007/11/28/scripting-the-leopard-terminal). godo lives at the excellent GitHub: http://github.com/mmower/godo/ and accepts patches."
64
64
  email:
65
65
  - self@mattmower.com
66
66
  executables:
@@ -79,12 +79,12 @@ files:
79
79
  - bin/godo
80
80
  - lib/godo.rb
81
81
  - lib/finder.rb
82
- - lib/iterm.rb
83
82
  - lib/project.rb
84
83
  - lib/session.rb
85
84
  - lib/template.yml
85
+ - lib/sessions/iterm_session.rb
86
86
  has_rdoc: true
87
- homepage: http://rubymatt.rubyforge.org/godo
87
+ homepage: http://simplyruby.rubyforge.org/godo
88
88
  post_install_message:
89
89
  rdoc_options:
90
90
  - --main
@@ -105,10 +105,10 @@ required_rubygems_version: !ruby/object:Gem::Requirement
105
105
  version:
106
106
  requirements: []
107
107
 
108
- rubyforge_project: rubymatt
108
+ rubyforge_project: simplyruby
109
109
  rubygems_version: 1.0.1
110
110
  signing_key:
111
111
  specification_version: 2
112
- summary: go (to project) do (stuffs) godo provides a smart way of opening a project folder and invoking a set of commands appropriate to that project
112
+ summary: go (to project) do (stuffs) godo provides a smart way of opening a project folder in multiple terminal tabs and, in each tab, invoking a commands appropriate to that project
113
113
  test_files:
114
114
  - test/test_godo.rb
metadata.gz.sig CHANGED
Binary file