godo 1.0.3 → 1.0.4

Sign up to get free protection for your applications and to get access to all the features.
data.tar.gz.sig CHANGED
Binary file
@@ -9,3 +9,4 @@ lib/project.rb
9
9
  lib/session.rb
10
10
  lib/template.yml
11
11
  lib/sessions/iterm_session.rb
12
+ lib/sessions/terminal_session.rb
data/README.txt CHANGED
@@ -32,7 +32,7 @@ creating controllers for other unixen should be straightforward if they can be c
32
32
 
33
33
  godo is a rewrite of my original 'gp' script (http://matt.blogs.it/entries/00002674.html) which fixes
34
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).
35
+ idea of using heuristics to detect project types from Solomon White's gp variant (http://onrails.org/articles/2007/11/28/scripting-the-leopard-terminal).
36
36
 
37
37
  godo lives at the excellent GitHub: http://github.com/mmower/godo/ and accepts patches.
38
38
 
@@ -41,6 +41,7 @@ godo lives at the excellent GitHub: http://github.com/mmower/godo/ and accepts p
41
41
  * All-in-one configuration file
42
42
  * Flexible heuristics for detecting project type
43
43
  * Flexible actions for running commands
44
+ * Project level customizations
44
45
 
45
46
  == SYNOPSIS:
46
47
 
@@ -54,8 +55,24 @@ godo <project>
54
55
 
55
56
  Where project is a search term that will match part of the project path name.
56
57
 
57
- To open a project and override the project type (i.e. do not use heuristics):
58
-
58
+ If the project has a .godo file at its root, then those actions will be used
59
+ instead of using the heuristics. A project level .godo file can reference
60
+ actions defined in ~/.godo, a group of actions by project type, and
61
+ arbitrary commands.
62
+
63
+ Here's a sample project level .godo file:
64
+ ---
65
+ actions:
66
+ - terminal
67
+ - command: echo 'tab before matcher'
68
+ label: This tab goes before the project matcher
69
+ - matcher: rails+git
70
+ - command: echo 'tab after matcher'
71
+ - terminal
72
+
73
+ To open a project and override the project type (i.e. do not use heuristics nor
74
+ a project level .godo file):
75
+
59
76
  godo -o <matcher> <project>
60
77
 
61
78
  == REQUIREMENTS:
data/Rakefile CHANGED
@@ -10,6 +10,7 @@ Hoe.new('godo', Godo::VERSION) do |p|
10
10
  p.extra_deps << ['trollop','>= 1.7']
11
11
  p.extra_deps << ['rb-appscript','>= 0.5.1']
12
12
  p.extra_deps << ['ick','>= 0.2.2']
13
+ p.extra_deps << ['highline','>= 1.4']
13
14
  p.remote_rdoc_dir = 'godo'
14
15
  end
15
16
 
@@ -7,17 +7,20 @@ module Godo
7
7
  # Find, if possible, a single project path matching the query string.
8
8
  #
9
9
  def self.find( query, options )
10
- let( Finder.new( options["projects"], options["ignores"] ) ) do |finder|
10
+ let( Finder.new( options["projects"], options["ignores"], options["max_depth"] ) ) do |finder|
11
11
  finder.find( Regexp.escape( query ) )
12
12
  end
13
13
  end
14
14
 
15
15
  # Create a Finder which will search under the given root folders, ignoring
16
- # folders that match any of the specified 'ignore' patterns.
16
+ # folders that match any of the specified 'ignore' patterns. Searches only
17
+ # max_depth folders below the root paths, searches unlimited depth if not
18
+ # specified.
17
19
  #
18
- def initialize( roots, ignores )
20
+ def initialize( roots, ignores, max_depth = 0 )
19
21
  @roots = roots.map { |root| File.expand_path( root ) }
20
22
  @ignores = ignores.map { |ignore| Regexp.compile( "/#{ignore}" ) }
23
+ @max_depth = max_depth.to_i
21
24
  end
22
25
 
23
26
  # Search for a folder matching the query.
@@ -49,6 +52,14 @@ module Godo
49
52
  @roots.each do |root|
50
53
  # puts "Searching for #{query} in #{root}"
51
54
  Find.find( root ) do |path|
55
+ if @max_depth > 0
56
+ # limit to @max_depth
57
+ partial_path = path.gsub(root, '')
58
+ Find.prune if partial_path =~ /\A\.+\Z/
59
+ depth = partial_path.split('/').length
60
+ Find.prune if depth > @max_depth + 1
61
+ end
62
+
52
63
  if filtered?( path )
53
64
  Find.prune
54
65
  elsif matches?( path, query )
@@ -1,7 +1,7 @@
1
1
  require 'yaml'
2
2
 
3
3
  module Godo
4
- VERSION = '1.0.3'
4
+ VERSION = '1.0.4'
5
5
  LIBPATH = File.expand_path( File.dirname( __FILE__ ) )
6
6
 
7
7
  # When called with no arguments this will return the path to the gem
@@ -37,18 +37,22 @@ module Godo
37
37
  config = YAML::load( File.read( File.expand_path( "~/.godo" ) ) )
38
38
  require 'finder'
39
39
  paths = Finder.find( query, config )
40
- if paths.empty?
40
+ found_path = if paths.empty?
41
41
  puts "No paths match for: #{query}"
42
42
  elsif paths.size > 1
43
+ require 'highline/import'
43
44
  puts "Multiple, ambgiuous, paths match for: #{query}"
44
- paths.each do |path|
45
- puts "\t#{path}"
46
- end
45
+ puts "Please pick one of the following:"
46
+ choose(*paths)
47
47
  else
48
48
  puts "Matching project: #{paths.first}"
49
+ paths.first
50
+ end
51
+
52
+ if found_path
49
53
  require 'project'
50
54
  project = Project.new( options, config )
51
- project.invoke( paths.first )
55
+ project.invoke( found_path )
52
56
  end
53
57
  end
54
58
 
@@ -24,12 +24,31 @@ module Godo
24
24
 
25
25
  private
26
26
  def invoke_actions( path, action_group )
27
- session = @session_class.new( path )
27
+ @session ||= @session_class.new( path )
28
28
 
29
- missing_actions = action_group.find_all { |action| !@actions.has_key?( action ) }
30
- if missing_actions.empty?
31
- action_group.each { |action_name|
32
- action = @actions[action_name]
29
+ action_group.each do |action_item|
30
+ action = case action_item
31
+ when String
32
+ @actions[action_item]
33
+ when Hash
34
+ if action_item["matcher"]
35
+ if matcher = @matchers.find { |matcher| matcher["name"] == action_item["matcher"] }
36
+ invoke_actions( path, matcher["actions"])
37
+ nil
38
+ else
39
+ puts "\tUnknown matcher: #{action_item["matcher"]}"
40
+ end
41
+ elsif action_item["command"]
42
+ action_item["label"] ||= action_item["command"]
43
+ action_item
44
+ else
45
+ puts "\tUnknown action type: #{action_item}"
46
+ end
47
+ else
48
+ puts "\tUnknown action type: #{action_item}"
49
+ end
50
+
51
+ if action
33
52
  exit = case action["exit"]
34
53
  when true
35
54
  true
@@ -42,13 +61,11 @@ module Godo
42
61
  else
43
62
  false
44
63
  end
45
-
46
- puts "\trunning: #{action_name} (exit: #{exit})"
47
- session.create( action["label"], action["command"], exit )
48
- }
49
- else
50
- missing_actions.each do |action|
51
- puts "\tMissing action: #{action}"
64
+
65
+ puts "\trunning: #{action["label"]} (exit: #{exit})"
66
+ @session.create( action["label"], action["command"], exit )
67
+ else
68
+ puts "\tMissing action: #{action_item.inspect}"
52
69
  end
53
70
  end
54
71
  end
@@ -57,6 +74,8 @@ module Godo
57
74
  if @options[:override]
58
75
  puts @options[:override]
59
76
  @matchers.find { |matcher| matcher["name"] == @options[:override] }
77
+ elsif File.file?( project_level_godo = File.join(path, '.godo' ) )
78
+ YAML::load( File.read( project_level_godo ) )
60
79
  else
61
80
  @matchers.detect { |matcher|
62
81
  matcher["heuristics"].all? { |heuristic|
@@ -0,0 +1,35 @@
1
+ require 'session'
2
+ require 'appscript'
3
+
4
+ module Godo
5
+
6
+ class TerminalSession < Session
7
+
8
+ def initialize( path )
9
+ super( path )
10
+ @@terminal ||= Appscript::app('Terminal')
11
+ @window = nil
12
+ end
13
+
14
+ def start
15
+ if @window
16
+ @window.frontmost.set(true)
17
+ Appscript::app('Terminal').activate
18
+ Appscript::app("System Events").application_processes["Terminal.app"].keystroke("t", :using => :command_down)
19
+ while (@window.tabs.last.busy.get)
20
+ # we're not on the new tab yet. wait a bit...
21
+ sleep 0.1
22
+ end
23
+ else
24
+ first_tab = @@terminal.do_script('')
25
+ @window = eval('Appscript::' + first_tab.to_s.gsub(/\.tabs.*$/, '')) # nasty hack. is there a legit way to find my mommy?
26
+ end
27
+ end
28
+
29
+ def execute( command )
30
+ @@terminal.do_script(command, :in => @window.tabs.last.get)
31
+ end
32
+
33
+ end
34
+
35
+ end
@@ -192,6 +192,11 @@ projects:
192
192
  - ~/Projects/rails
193
193
  - ~/Projects/Cocoa
194
194
 
195
- # The session controller to use. Right now iTerm is the only
196
- # game in town.
195
+ # Specifies how far down to search into the project root paths,
196
+ # defaults to unlimited depth.
197
+ # max_depth: 2
198
+
199
+ # The session controller to use. Right now iTerm and Terminal are the
200
+ # only options.
197
201
  sessions: ITermSession
202
+ # sessions: TerminalSession
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.3
4
+ version: 1.0.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - Matt Mower
@@ -30,7 +30,7 @@ cert_chain:
30
30
  yMQ/kUco
31
31
  -----END CERTIFICATE-----
32
32
 
33
- date: 2008-03-09 00:00:00 +00:00
33
+ date: 2008-03-11 00:00:00 +00:00
34
34
  default_executable:
35
35
  dependencies:
36
36
  - !ruby/object:Gem::Dependency
@@ -60,6 +60,15 @@ dependencies:
60
60
  - !ruby/object:Gem::Version
61
61
  version: 0.2.2
62
62
  version:
63
+ - !ruby/object:Gem::Dependency
64
+ name: highline
65
+ version_requirement:
66
+ version_requirements: !ruby/object:Gem::Requirement
67
+ requirements:
68
+ - - ">="
69
+ - !ruby/object:Gem::Version
70
+ version: "1.4"
71
+ version:
63
72
  - !ruby/object:Gem::Dependency
64
73
  name: hoe
65
74
  version_requirement:
@@ -69,7 +78,7 @@ dependencies:
69
78
  - !ruby/object:Gem::Version
70
79
  version: 1.5.1
71
80
  version:
72
- 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."
81
+ 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 White's 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."
73
82
  email:
74
83
  - self@mattmower.com
75
84
  executables:
@@ -92,6 +101,7 @@ files:
92
101
  - lib/session.rb
93
102
  - lib/template.yml
94
103
  - lib/sessions/iterm_session.rb
104
+ - lib/sessions/terminal_session.rb
95
105
  has_rdoc: true
96
106
  homepage: http://simplyruby.rubyforge.org/godo
97
107
  post_install_message:
metadata.gz.sig CHANGED
Binary file