go 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,42 @@
1
+ GO - Iterm-Rails
2
+ ===================
3
+
4
+ A script to launch commands in differents iTerm tabs for a Rails project: console, server, mate...
5
+ inspired by http://github.com/chrisjpowers/iterm_window examples
6
+
7
+ Examples:
8
+ --------------
9
+
10
+ iterm-rails /path/to/project
11
+
12
+ iterm-rails project # you can set a default project directory (see configuration options below)
13
+
14
+
15
+ Configuration:
16
+ --------------
17
+ You can override default configuration options:
18
+
19
+ - globally in ~/.iterm-rails.config
20
+
21
+ - per project in project/.iterm-rails.config
22
+
23
+
24
+ Configuration options in DEFAULT_CONFIG:
25
+ ----------------------------------------
26
+
27
+ DEFAULT_CONFIG = {
28
+ :projects_dir => Dir.getwd,
29
+ :launch_server => true,
30
+ :launch_console => true,
31
+ :launch_spork_for_rspec => false,
32
+ :launch_spork_for_cuc => false,
33
+ :rails3 => false,
34
+ :prepend_command => nil, # example: 'rvm ruby-1.9.2-head'
35
+ }
36
+
37
+ Author
38
+ ------
39
+
40
+ - Florent Guilleux (Author): github.com/Florent2 | florent2 AT gmail DOT com
41
+
42
+ - Alvaro Pereyra (Contributor): github.com/xenda | alvaro AT xendacentral DOT com
@@ -0,0 +1,35 @@
1
+ #!/usr/bin/env gem build
2
+ # encoding: utf-8
3
+
4
+ require "base64"
5
+
6
+ Gem::Specification.new do |s|
7
+ s.name = "go"
8
+ s.version = "0.0.1"
9
+ s.authors = ["Florent Guilleux", "Alvaro Pereyra"]
10
+ s.homepage = "http://github.com/xenda/iterm-rails"
11
+ s.summary = "A script to launch commands in differents iTerm tabs for a Rails project"
12
+ s.description = "#{s.summary}. inspired by http://github.com/chrisjpowers/iterm_window examples."
13
+ s.cert_chain = nil
14
+ s.email = Base64.decode64("YWx2YXJvQHhlbmRhY2VudHJhbC5jb20=\n")
15
+ s.has_rdoc = false
16
+
17
+ # files
18
+ s.files = `git ls-files`.split("\n")
19
+
20
+ Dir["bin/*"].map(&File.method(:basename))
21
+ s.default_executable = "go"
22
+ s.require_paths = ["lib"]
23
+
24
+ # Ruby version
25
+ s.required_ruby_version = ::Gem::Requirement.new("~> 1.9")
26
+
27
+ begin
28
+ require "changelog"
29
+ rescue LoadError
30
+ warn "You have to have changelog gem installed for post install message"
31
+ else
32
+ s.post_install_message = CHANGELOG.new.version_changes
33
+ end
34
+
35
+ end
@@ -0,0 +1 @@
1
+ require "iterm_rails"
@@ -0,0 +1,130 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ # a script to launch commands in differents iTerm tabs for a Rails project: console, server, mate...
4
+ # inspired by http://github.com/chrisjpowers/iterm_window examples
5
+
6
+ # examples:
7
+ # iterm-rails /path/to/project
8
+ # iterm-rails project # you can set a default project directory (see configuration options below)
9
+
10
+ # you can override default configuration options:
11
+ # globally in ~/.iterm-rails.config
12
+ # per project in project/.iterm-rails.config
13
+ # see configuration options in DEFAULT_CONFIG below
14
+
15
+
16
+ require 'rubygems'
17
+ require 'iterm_window'
18
+ require 'pathname'
19
+ require 'yaml'
20
+ require 'socket'
21
+ require 'timeout'
22
+
23
+ module ItermRails
24
+
25
+ DEFAULT_CONFIG = {
26
+ :projects_dir => Dir.getwd,
27
+ :launch_server => true,
28
+ :launch_console => true,
29
+ :launch_spork_for_rspec => false,
30
+ :launch_spork_for_cuc => false,
31
+ :rails3 => false,
32
+ :prepend_command => nil, # example: 'rvm ruby-1.9.2-head'
33
+ }
34
+
35
+ def create_tab(project_path, *commands)
36
+ project_name = project_path.basename
37
+ open_tab :new_tab do
38
+ write "cd #{project_path}"
39
+ set_title "- #{project_name}"
40
+ end
41
+ end
42
+
43
+ def find_available_port_from(port_number)
44
+ result = port_number
45
+ result += 1 while is_port_open?(result)
46
+ result
47
+ end
48
+
49
+ def is_a_rails_project_directory?(project_path)
50
+ %w{app config db script}.all? { |directory| project_path.join(directory).exist? }
51
+ end
52
+
53
+ # from http://stackoverflow.com/questions/517219/ruby-see-if-a-port-is-open
54
+ def is_port_open?(port_number)
55
+ begin
56
+ Timeout::timeout(1) do
57
+ begin
58
+ s = TCPSocket.new('localhost', port_number)
59
+ s.close
60
+ return true
61
+ rescue Errno::ECONNREFUSED, Errno::EHOSTUNREACH
62
+ return false
63
+ end
64
+ end
65
+ rescue Timeout::Error
66
+ end
67
+
68
+ return false
69
+ end
70
+
71
+ def merge_configs(config, custom_config_file_path)
72
+ if custom_config_file_path.exist?
73
+ config.merge YAML::load(File.open custom_config_file_path)
74
+ else
75
+ config
76
+ end
77
+ end
78
+
79
+ config = merge_configs DEFAULT_CONFIG, Pathname.new('~').expand_path.join('.iterm-rails.config')
80
+
81
+ raise "missing project path" if ARGV.first.nil?
82
+ project_path = Pathname.new ARGV.first
83
+ project_path = Pathname.new(config[:projects_dir]).join(project_path) if project_path.relative?
84
+ project_path = project_path.expand_path
85
+ raise "'#{project_path}' does not exist or is not a directory" if !project_path.directory?
86
+ raise "'#{project_path}' is not a Rails project directory" if !is_a_rails_project_directory?(project_path)
87
+ config = merge_configs config, project_path.join('.iterm-rails.config')
88
+
89
+ puts "open new window with tabs for '#{project_path}'"
90
+ puts " with config: #{config.inspect}"
91
+
92
+ Tab = Struct.new :title, :commands
93
+ tabs = []
94
+
95
+ if config[:launch_spork_for_rspec]
96
+ port = find_available_port_from 8989
97
+ tabs << Tab.new("spork #{port}", ["spork -p #{port}"])
98
+ end
99
+
100
+ if config[:launch_spork_for_cuc]
101
+ port = find_available_port_from 9989
102
+ tabs << Tab.new("spork cuc #{port}", ["spork cuc -p #{port}"])
103
+ end
104
+
105
+ if config[:launch_console]
106
+ command = if config[:rails3] then "rails console" else "script/console" end
107
+ tabs << Tab.new("console", [command])
108
+ end
109
+
110
+ tabs << Tab.new("main", ["mate ./ &"])
111
+
112
+ if config[:launch_console]
113
+ port = find_available_port_from 3000
114
+ command = if config[:rails3] then "rails server" else "script/server" end
115
+ tabs << Tab.new("server #{port}", ["#{command} -p #{port}"])
116
+ end
117
+
118
+ ItermWindow.open do
119
+ project_name = project_path.basename
120
+ tabs.each do |tab|
121
+ open_tab :new_tab do
122
+ write "cd #{project_path}"
123
+ write config[:prepend_command] unless config[:prepend_command] == "nil" || config[:prepend_command].empty?
124
+ tab.commands.each { |command| write command }
125
+ set_title "#{tab.title} - #{project_name}"
126
+ end
127
+ end
128
+ end
129
+
130
+ end
metadata ADDED
@@ -0,0 +1,66 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: go
3
+ version: !ruby/object:Gem::Version
4
+ prerelease: false
5
+ segments:
6
+ - 0
7
+ - 0
8
+ - 1
9
+ version: 0.0.1
10
+ platform: ruby
11
+ authors:
12
+ - Florent Guilleux
13
+ - Alvaro Pereyra
14
+ autorequire:
15
+ bindir: bin
16
+ cert_chain:
17
+ date: 2010-04-13 00:00:00 -05:00
18
+ default_executable: go
19
+ dependencies: []
20
+
21
+ description: A script to launch commands in differents iTerm tabs for a Rails project. inspired by http://github.com/chrisjpowers/iterm_window examples.
22
+ email: alvaro@xendacentral.com
23
+ executables: []
24
+
25
+ extensions: []
26
+
27
+ extra_rdoc_files: []
28
+
29
+ files:
30
+ - README.markdown
31
+ - iterm_rails.gemspec
32
+ - iterm_rails.rb
33
+ - lib/iterm_rails.rb
34
+ has_rdoc: true
35
+ homepage: http://github.com/xenda/iterm-rails
36
+ licenses: []
37
+
38
+ post_install_message:
39
+ rdoc_options: []
40
+
41
+ require_paths:
42
+ - lib
43
+ required_ruby_version: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - ~>
46
+ - !ruby/object:Gem::Version
47
+ segments:
48
+ - 1
49
+ - 9
50
+ version: "1.9"
51
+ required_rubygems_version: !ruby/object:Gem::Requirement
52
+ requirements:
53
+ - - ">="
54
+ - !ruby/object:Gem::Version
55
+ segments:
56
+ - 0
57
+ version: "0"
58
+ requirements: []
59
+
60
+ rubyforge_project:
61
+ rubygems_version: 1.3.6
62
+ signing_key:
63
+ specification_version: 3
64
+ summary: A script to launch commands in differents iTerm tabs for a Rails project
65
+ test_files: []
66
+