dkastner-tmuxinator 0.4.0

Sign up to get free protection for your applications and to get access to all the features.
data/.document ADDED
@@ -0,0 +1,5 @@
1
+ lib/**/*.rb
2
+ bin/*
3
+ -
4
+ features/**/*.feature
5
+ LICENSE.txt
data/.rspec ADDED
@@ -0,0 +1 @@
1
+ --color
data/Gemfile ADDED
@@ -0,0 +1,8 @@
1
+ source "http://rubygems.org"
2
+
3
+ group :development do
4
+ gem "rspec", "~> 2.1.0"
5
+ gem "bundler", "~> 1.0.0"
6
+ gem "jeweler", "~> 1.5.1"
7
+ gem "rcov", ">= 0"
8
+ end
data/Gemfile.lock ADDED
@@ -0,0 +1,28 @@
1
+ GEM
2
+ remote: http://rubygems.org/
3
+ specs:
4
+ diff-lcs (1.1.2)
5
+ git (1.2.5)
6
+ jeweler (1.5.1)
7
+ bundler (~> 1.0.0)
8
+ git (>= 1.2.5)
9
+ rake
10
+ rake (0.8.7)
11
+ rcov (0.9.9)
12
+ rspec (2.1.0)
13
+ rspec-core (~> 2.1.0)
14
+ rspec-expectations (~> 2.1.0)
15
+ rspec-mocks (~> 2.1.0)
16
+ rspec-core (2.1.0)
17
+ rspec-expectations (2.1.0)
18
+ diff-lcs (~> 1.1.2)
19
+ rspec-mocks (2.1.0)
20
+
21
+ PLATFORMS
22
+ ruby
23
+
24
+ DEPENDENCIES
25
+ bundler (~> 1.0.0)
26
+ jeweler (~> 1.5.1)
27
+ rcov
28
+ rspec (~> 2.1.0)
data/LICENSE.txt ADDED
@@ -0,0 +1,20 @@
1
+ Copyright (c) 2010 Allen Bargi
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining
4
+ a copy of this software and associated documentation files (the
5
+ "Software"), to deal in the Software without restriction, including
6
+ without limitation the rights to use, copy, modify, merge, publish,
7
+ distribute, sublicense, and/or sell copies of the Software, and to
8
+ permit persons to whom the Software is furnished to do so, subject to
9
+ the following conditions:
10
+
11
+ The above copyright notice and this permission notice shall be
12
+ included in all copies or substantial portions of the Software.
13
+
14
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
17
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
18
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
19
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
20
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,148 @@
1
+ # Tmuxinator
2
+
3
+ Create and manage tmux and iTerm2 sessions easily. Fork of ([Tmuxinator](https://github.com/aziz/tmuxinator)).
4
+
5
+ Note: while [Terminitor](http://github.com/achiu/terminitor) has iTerm support, it relies on sending keypresses to iTerm. This project uses AppleScript and can, therefore, connect with iTerm on a deeper level. I also like tmuxinator's config format and it's nice to have one config that can be used on a Mac or a non-GUI'd machine.
6
+
7
+ ## Installation
8
+
9
+ $ gem install dkastner-tmuxinator
10
+
11
+ Note: This fork plays well with existing tmuxinator installs.
12
+
13
+ Then follow the instructions. You just have to drop a line in your ~/.bashrc file, similar to RVM if you've used that before:
14
+
15
+ [[ -s $HOME/.tmuxinator/scripts/tmuxinator ]] && source $HOME/.tmuxinator/scripts/tmuxinator
16
+
17
+ ## Editor and Shell
18
+
19
+ tmuxinator uses your shell's default editor for opening files. If you're not sure what that is type:
20
+
21
+ $ echo $EDITOR
22
+
23
+ For me that produces "vim"
24
+ If you want to change your default editor simple put a line in ~/.bash_profile that changes it. Mine looks like this:
25
+
26
+ export EDITOR='vim'
27
+
28
+ It also uses $SHELL variable. which is always set by your shell.
29
+
30
+ ## Usage
31
+
32
+
33
+ ### Create a project ###
34
+
35
+ $ tmuxinator new project_name
36
+
37
+ Create or edit your projects with this command, for editing you can also use `tmuxinator open project_name`. `new` aliased to `o`,`open` and `n`. Your default editor ($EDITOR) is used to open the file. If this is a new project you will see this default config:
38
+
39
+ # ~/.tmuxinator/project_name.yml
40
+ # you can make as many tabs as you wish...
41
+
42
+ project_name: Tmuxinator
43
+ project_root: ~/code/rails_project
44
+ rvm: 1.9.2@rails_project
45
+ pre: sudo /etc/rc.d/mysqld start
46
+ tabs:
47
+ - editor:
48
+ layout: main-vertical
49
+ panes:
50
+ - vim
51
+ - #empty, will just run plain bash
52
+ - top
53
+ - shell: git pull
54
+ - database: rails db
55
+ - server: rails s
56
+ - logs: tail -f logs/development.log
57
+ - console: rails c
58
+ - capistrano:
59
+ - server: ssh me@myhost
60
+
61
+
62
+ If a tab contains multiple commands, they will be 'joined' together with '&&'.
63
+ If you want to have your own default config, place it into $HOME/.tmuxinator/default.yml
64
+
65
+ The `pre` command allows you to run anything before starting the tmux/iTerm session. Could be handy to make sure you database daemons are running. Multiple commands can be specified, just like for tabs.
66
+
67
+ ## Panes Support
68
+ you can define your own panes inside a window likes this:
69
+
70
+ - window_with_panes
71
+ layout: main-vertical
72
+ panes:
73
+ - vim
74
+ - #empty, will just run plain bash
75
+ - top
76
+
77
+
78
+ ## Starting a project
79
+
80
+ $ start_project_name
81
+
82
+ This will fire up tmux with all the tabs you configured.
83
+
84
+ $ iterm_project_name
85
+
86
+ This will fire up iTerm with all the tabs you configured.
87
+
88
+ ### Limitations ###
89
+
90
+ After you create a project, you will have to open a new shell window. This is because tmuxinator adds an
91
+ alias to bash (or any other shell you use, like zsh) to open tmux with the project config. You can reload your shell rc file
92
+ instead of openning a new window like this, for instance in bash you could do this:
93
+
94
+ $ source ~/.bashrc
95
+
96
+ ## Other Commands
97
+
98
+ $ tmuxinator copy existing_project new_project
99
+
100
+ Copy an existing project. aliased to `c`
101
+
102
+
103
+ $ tmuxinator update_scripts
104
+
105
+ Re-create the tmux and iTerm scripts and aliases from the configs. Use this only if you edit your project configs outside of tmuxinator, i.e. not using "tmuxinator open xxx".
106
+
107
+
108
+ $ tmuxinator list
109
+
110
+ List all the projects you have configured. aliased to `l`
111
+
112
+
113
+ $ tmuxinator delete project_name
114
+
115
+ Remove a project
116
+
117
+
118
+ $ tmuxinator implode
119
+
120
+ Remove all tmuxinator configs, aliases and scripts. aliased to `i`
121
+
122
+ $ tmuxinator doctor
123
+
124
+ Examines your environment and identifies problems with your configuration
125
+
126
+
127
+ $ tmuxinator version
128
+
129
+ shows tmuxinator's version. aliased to `v`
130
+
131
+
132
+ $ tmuxinator help
133
+
134
+ shows tmuxinator's help. aliased to `h`
135
+
136
+ ## Contributing to tmuxinator
137
+
138
+ * Check out the latest master to make sure the feature hasn't been implemented or the bug hasn't been fixed yet
139
+ * Check out the issue tracker to make sure someone already hasn't requested it and/or contributed it
140
+ * Fork the project
141
+ * Start a feature/bugfix branch
142
+ * Commit and push until you are happy with your contribution
143
+ * Make sure to add tests for it. This is important so I don't break it in a future version unintentionally.
144
+ * Please try not to mess with the Rakefile, version, or history. If you want to have your own version, or is otherwise necessary, that is fine, but please isolate to its own commit so I can cherry-pick around it.
145
+
146
+ ## Copyright
147
+
148
+ Copyright (c) 2010 Derek Kastner. See LICENSE.txt for further details.
data/Rakefile ADDED
@@ -0,0 +1,72 @@
1
+ require 'rubygems'
2
+ require 'bundler'
3
+ begin
4
+ Bundler.setup(:default, :development)
5
+ rescue Bundler::BundlerError => e
6
+ $stderr.puts e.message
7
+ $stderr.puts "Run `bundle install` to install missing gems"
8
+ exit e.status_code
9
+ end
10
+ require 'rake'
11
+
12
+ require 'jeweler'
13
+ Jeweler::Tasks.new do |gem|
14
+ # gem is a Gem::Specification... see http://docs.rubygems.org/read/chapter/20 for more options
15
+ gem.name = "tmuxinator"
16
+ gem.homepage = "http://github.com/aziz/tmuxinator"
17
+ gem.license = "MIT"
18
+ gem.summary = %Q{Create and manage complex tmux sessions easily.}
19
+ gem.description = %Q{Create and manage complex tmux sessions easily.}
20
+ gem.email = "allen.bargi@gmail.com"
21
+ gem.authors = ["Allen Bargi"]
22
+ gem.post_install_message = %{
23
+ __________________________________________________________
24
+ ..........................................................
25
+
26
+ Thank you for installing tmuxinator
27
+ Please be sure to to drop a line in your ~/.bashrc file, similar
28
+ to RVM if you've used that before:
29
+
30
+ [[ -s $HOME/.tmuxinator/scripts/tmuxinator ]] && source $HOME/.tmuxinator/scripts/tmuxinator
31
+
32
+ also ensure that you've set these variables in your ENV:
33
+
34
+ $EDITOR, $SHELL
35
+
36
+ you can run `tmuxinator doctor` to make sure everything is set.
37
+ happy tmuxing with tmuxinator!
38
+
39
+ ..........................................................
40
+ __________________________________________________________
41
+
42
+ }
43
+
44
+ # Include your dependencies below. Runtime dependencies are required when using your gem,
45
+ # and development dependencies are only needed for development (ie running rake tasks, tests, etc)
46
+ # gem.add_runtime_dependency 'jabber4r', '> 0.1'
47
+ # gem.add_development_dependency 'rspec', '> 1.2.3'
48
+ end
49
+ Jeweler::RubygemsDotOrgTasks.new
50
+
51
+ require 'rspec/core'
52
+ require 'rspec/core/rake_task'
53
+ RSpec::Core::RakeTask.new(:spec) do |spec|
54
+ spec.pattern = FileList['spec/**/*_spec.rb']
55
+ end
56
+
57
+ RSpec::Core::RakeTask.new(:rcov) do |spec|
58
+ spec.pattern = 'spec/**/*_spec.rb'
59
+ spec.rcov = true
60
+ end
61
+
62
+ task :default => :spec
63
+
64
+ require 'rake/rdoctask'
65
+ Rake::RDocTask.new do |rdoc|
66
+ version = File.exist?('VERSION') ? File.read('VERSION') : ""
67
+
68
+ rdoc.rdoc_dir = 'rdoc'
69
+ rdoc.title = "tmuxinator #{version}"
70
+ rdoc.rdoc_files.include('README*')
71
+ rdoc.rdoc_files.include('lib/**/*.rb')
72
+ end
data/VERSION ADDED
@@ -0,0 +1 @@
1
+ 0.3.4
data/bin/tmuxinator ADDED
@@ -0,0 +1,6 @@
1
+ #!/usr/bin/env ruby
2
+ $:.unshift(File.dirname(__FILE__) + '/../lib') unless $:.include?(File.dirname(__FILE__) + '/../lib')
3
+
4
+ require 'tmuxinator'
5
+
6
+ Tmuxinator::Cli.start(*ARGV)
@@ -0,0 +1,90 @@
1
+ Gem::Specification.new do |s|
2
+ s.name = %q{dkastner-tmuxinator}
3
+ s.version = "0.4.0"
4
+
5
+ s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
6
+ s.authors = ["Derek Kastner"]
7
+ s.date = %q{2011-06-20}
8
+ s.default_executable = %q{tmuxinator}
9
+ s.description = %q{Create and manage complex tmux and iTerm sessions easily.}
10
+ s.email = %q{dkastner@gmail.com}
11
+ s.executables = ["tmuxinator"]
12
+ s.extra_rdoc_files = [
13
+ "LICENSE.txt",
14
+ "README.md"
15
+ ]
16
+ s.files = [
17
+ ".document",
18
+ ".rspec",
19
+ "Gemfile",
20
+ "Gemfile.lock",
21
+ "LICENSE.txt",
22
+ "README.md",
23
+ "Rakefile",
24
+ "VERSION",
25
+ "bin/tmuxinator",
26
+ "lib/tmuxinator.rb",
27
+ "lib/tmuxinator/assets/iterm.AppleScript",
28
+ "lib/tmuxinator/assets/sample.yml",
29
+ "lib/tmuxinator/assets/tmux_config.tmux",
30
+ "lib/tmuxinator/cli.rb",
31
+ "lib/tmuxinator/config_writer.rb",
32
+ "lib/tmuxinator/iterm_config_writer.rb",
33
+ "lib/tmuxinator/helper.rb",
34
+ "spec/spec_helper.rb",
35
+ "spec/tmuxinator_spec.rb",
36
+ "dkastner-tmuxinator.gemspec"
37
+ ]
38
+ s.homepage = %q{http://github.com/dkastner/tmuxinator}
39
+ s.licenses = ["MIT"]
40
+ s.post_install_message = %q{
41
+ __________________________________________________________
42
+ ..........................................................
43
+
44
+ Thank you for installing tmuxinator
45
+ Please be sure to to drop a line in your ~/.bashrc file, similar
46
+ to RVM if you've used that before:
47
+
48
+ [[ -s $HOME/.tmuxinator/scripts/tmuxinator ]] && source $HOME/.tmuxinator/scripts/tmuxinator
49
+
50
+ also ensure that you've set these variables in your ENV:
51
+
52
+ $EDITOR, $SHELL
53
+
54
+ you can run `tmuxinator doctor` to make sure everything is set.
55
+ happy tmuxing with tmuxinator!
56
+
57
+ ..........................................................
58
+ __________________________________________________________
59
+
60
+ }
61
+ s.require_paths = ["lib"]
62
+ s.rubygems_version = %q{1.6.2}
63
+ s.summary = %q{Create and manage complex tmux sessions easily.}
64
+ s.test_files = [
65
+ "spec/spec_helper.rb",
66
+ "spec/tmuxinator_spec.rb"
67
+ ]
68
+
69
+ if s.respond_to? :specification_version then
70
+ s.specification_version = 3
71
+
72
+ if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
73
+ s.add_development_dependency(%q<rspec>, ["~> 2.1.0"])
74
+ s.add_development_dependency(%q<bundler>, ["~> 1.0.0"])
75
+ s.add_development_dependency(%q<jeweler>, ["~> 1.5.1"])
76
+ s.add_development_dependency(%q<rcov>, [">= 0"])
77
+ else
78
+ s.add_dependency(%q<rspec>, ["~> 2.1.0"])
79
+ s.add_dependency(%q<bundler>, ["~> 1.0.0"])
80
+ s.add_dependency(%q<jeweler>, ["~> 1.5.1"])
81
+ s.add_dependency(%q<rcov>, [">= 0"])
82
+ end
83
+ else
84
+ s.add_dependency(%q<rspec>, ["~> 2.1.0"])
85
+ s.add_dependency(%q<bundler>, ["~> 1.0.0"])
86
+ s.add_dependency(%q<jeweler>, ["~> 1.5.1"])
87
+ s.add_dependency(%q<rcov>, [">= 0"])
88
+ end
89
+ end
90
+
data/lib/tmuxinator.rb ADDED
@@ -0,0 +1,13 @@
1
+ require 'yaml'
2
+ require 'ostruct'
3
+ require 'erb'
4
+ require 'tmuxinator/helper'
5
+ require 'tmuxinator/cli'
6
+ require 'tmuxinator/config_writer'
7
+ require 'tmuxinator/iterm_config_writer'
8
+
9
+ TMUX_TEMPLATE = "#{File.dirname(__FILE__)}/tmuxinator/assets/tmux_config.tmux"
10
+ ITERM_TEMPLATE = "#{File.dirname(__FILE__)}/tmuxinator/assets/iterm.AppleScript"
11
+
12
+ module Tmuxinator
13
+ end
@@ -0,0 +1,46 @@
1
+ tell application "iTerm"
2
+ activate
3
+
4
+ set myterm to (make new terminal)
5
+
6
+ set the name of the first window to "<%= @project_name %>"
7
+
8
+ tell myterm
9
+ set number of columns to 100
10
+ set number of rows to 50
11
+
12
+ -- set up tabs and panes
13
+ <% @tabs.each_with_index do |tab, i| %>
14
+ <% session = "session#{i}" %>
15
+
16
+ -- tab "<%= tab.name %>"
17
+ set <%= session %> to (launch session "<%= tab.name %>")
18
+
19
+ tell <%= session %>
20
+ <% if tab.command %>
21
+ write text "cd <%= @project_root %> && <%= tab.command %>"
22
+ <% elsif tab.panes %>
23
+ -- tmux select-layout -t <%= window(i+1) %> <%=s tab.layout %>
24
+ write text "cd <%= @project_root %> && <%= tab.panes.shift %>"
25
+ <% tab.panes.each do |pane| %>
26
+ tell application "System Events" to keystroke "d" using command down
27
+ write text "cd <%= @project_root %> && <%= pane %>"
28
+ <% end %>
29
+ <% end %>
30
+ end tell
31
+ <% end %>
32
+
33
+ <% if @pre %>
34
+ set pre_session to (launch session "pre")
35
+ tell pre_session
36
+ -- run the pre stuff
37
+ write text "<%= @pre.kind_of?(Array) ? @pre.join(" && ") : @pre %>"
38
+ end tell
39
+ terminate pre_session
40
+ <% end %>
41
+
42
+ end tell
43
+
44
+ -- select window 1
45
+ select the first session of myterm
46
+ end tell
@@ -0,0 +1,21 @@
1
+ # ~/.tmuxinator/<%= @name %>.yml
2
+ # you can make as many tabs as you wish...
3
+
4
+ project_name: Tmuxinator
5
+ project_root: ~/code/rails_project
6
+ rvm: 1.9.2@rails_project
7
+ pre: sudo /etc/rc.d/mysqld start
8
+ tabs:
9
+ - editor:
10
+ layout: main-vertical
11
+ panes:
12
+ - vim
13
+ - #empty, will just run plain bash
14
+ - top
15
+ - shell: git pull
16
+ - database: rails db
17
+ - server: rails s
18
+ - logs: tail -f logs/development.log
19
+ - console: rails c
20
+ - capistrano:
21
+ - server: ssh me@myhost
@@ -0,0 +1,37 @@
1
+ #!<%= ENV['SHELL'] || '/bin/bash' %>
2
+ tmux start-server
3
+
4
+ if ! $(tmux has-session -t <%=s @project_name %>); then
5
+ cd <%= @project_root || "." %>
6
+ <%= @pre.kind_of?(Array) ? @pre.join(" && ") : @pre %>
7
+ env TMUX= tmux start-server \; set-option -g base-index 1 \; new-session -d -s <%=s @project_name %> -n <%=s @tabs[0].name %>
8
+ tmux set-option -t <%=s @project_name %> default-path <%= @project_root %>
9
+
10
+ <% @tabs[1..-1].each_with_index do |tab, i| %>
11
+ tmux new-window -t <%= window(i+2) %> -n <%=s tab.name %>
12
+ <% end %>
13
+
14
+ # set up tabs and panes
15
+ <% @tabs.each_with_index do |tab, i| %>
16
+ # tab "<%= tab.name %>"
17
+ <% if tab.command %>
18
+ <%= send_keys(tab.command, i+1) %>
19
+ <% elsif tab.panes %>
20
+ <%= send_keys(tab.panes.shift, i+1) %>
21
+ <% tab.panes.each do |pane| %>
22
+ tmux splitw -t <%= window(i+1) %>
23
+ <%= send_keys(pane, i+1) %>
24
+ <% end %>
25
+ tmux select-layout -t <%= window(i+1) %> <%=s tab.layout %>
26
+ <% end %>
27
+ <% end %>
28
+
29
+ tmux select-window -t <%= window(1) %>
30
+
31
+ fi
32
+
33
+ if [ -z $TMUX ]; then
34
+ tmux -u attach-session -t <%=s @project_name %>
35
+ else
36
+ tmux -u switch-client -t <%=s @project_name %>
37
+ fi
@@ -0,0 +1,182 @@
1
+ require 'fileutils'
2
+
3
+ module Tmuxinator
4
+ class Cli
5
+
6
+ class << self
7
+ include Tmuxinator::Helper
8
+
9
+ def start *args
10
+ if args.empty?
11
+ self.usage
12
+ else
13
+ self.send(args.shift, *args)
14
+ end
15
+ end
16
+
17
+ # print the usage string, this is a fall through method.
18
+ def usage
19
+ puts %{
20
+ Usage: tmuxinator ACTION [Arg]
21
+
22
+ ACTIONS:
23
+ open [project_name]
24
+ create a new project file and open it in your editor
25
+ copy [source_project] [new_project]
26
+ copy source_project project file to a new project called new_project
27
+ delete [project_name]
28
+ deletes the project called project_name
29
+ update_scripts
30
+ re-create the tmux scripts and aliases from the configs
31
+ implode
32
+ deletes all existing projects!
33
+ list [-v]
34
+ list all existing projects
35
+ doctor
36
+ look for problems in your configuration
37
+ help
38
+ shows this help document
39
+ version
40
+
41
+ }
42
+ end
43
+ alias :help :usage
44
+ alias :h :usage
45
+
46
+ # Open a config file, it's created if it doesn't exist already.
47
+ def open *args
48
+ exit!("You must specify a name for the new project") unless args.size > 0
49
+ puts "warning: passing multiple arguments to open will be ignored" if args.size > 1
50
+ @name = args.shift
51
+ FileUtils.mkdir_p(root_dir+"scripts")
52
+ config_path = "#{root_dir}#{@name}.yml"
53
+ unless File.exists?(config_path)
54
+ template = File.exists?(user_config) ? user_config : "#{File.dirname(__FILE__)}/assets/sample.yml"
55
+ erb = ERB.new(File.read(template)).result(binding)
56
+ tmp = File.open(config_path, 'w') {|f| f.write(erb) }
57
+ end
58
+ system("$EDITOR #{config_path}")
59
+ update_scripts
60
+ end
61
+ alias :o :open
62
+ alias :new :open
63
+ alias :n :open
64
+
65
+ def copy *args
66
+ @copy = args.shift
67
+ @name = args.shift
68
+ @config_to_copy = "#{root_dir}#{@copy}.yml"
69
+
70
+ exit!("Project #{@copy} doesn't exist!") unless File.exists?(@config_to_copy)
71
+ exit!("You must specify a name for the new project") unless @name
72
+
73
+ file_path = "#{root_dir}#{@name}.yml"
74
+
75
+ if File.exists?(file_path)
76
+ confirm!("#{@name} already exists, would you like to overwrite it? (type yes or no):") do
77
+ FileUtils.rm(file_path)
78
+ puts "Overwriting #{@name}"
79
+ end
80
+ end
81
+ open @name
82
+ end
83
+ alias :c :copy
84
+
85
+ def delete *args
86
+ puts "warning: passing multiple arguments to delete will be ignored" if args.size > 1
87
+ filename = args.shift
88
+ file_path = "#{root_dir}#{filename}.yml"
89
+
90
+ if File.exists?(file_path)
91
+ confirm!("Are you sure you want to delete #{filename}? (type yes or no):") do
92
+ FileUtils.rm(file_path)
93
+ puts "Deleted #{filename}"
94
+ end
95
+ else
96
+ exit! "That file doesn't exist."
97
+ end
98
+ end
99
+ alias :d :delete
100
+
101
+ def implode *args
102
+ exit!("delete_all doesn't accapt any arguments!") unless args.empty?
103
+ confirm!("Are you sure you want to delete all tmuxinator configs? (type yes or no):") do
104
+ FileUtils.remove_dir(root_dir)
105
+ puts "Deleted #{root_dir}"
106
+ end
107
+ end
108
+ alias :i :implode
109
+
110
+ def list *args
111
+ verbose = args.include?("-v")
112
+ puts "tmuxinator configs:"
113
+ Dir["#{root_dir}**"].each do |path|
114
+ next unless verbose || File.extname(path) == ".yml"
115
+ path = path.gsub(root_dir, '').gsub('.yml','') unless verbose
116
+ puts " #{path}"
117
+ end
118
+ end
119
+ alias :l :list
120
+ alias :ls :list
121
+
122
+ def version
123
+ system("cat #{File.dirname(__FILE__) + '/../../VERSION'}")
124
+ puts
125
+ end
126
+ alias :v :version
127
+
128
+ def update_scripts
129
+ Dir["#{root_dir}*.tmux"].each {|p| FileUtils.rm(p) }
130
+ Dir["#{root_dir}*.AppleScript"].each {|p| FileUtils.rm(p) }
131
+
132
+ aliases = []
133
+ Dir["#{root_dir}*.yml"].each do |path|
134
+ aliases << Tmuxinator::ConfigWriter.new(path).write!
135
+ end
136
+
137
+ Dir["#{root_dir}*.yml"].each do |path|
138
+ aliases << Tmuxinator::ITermConfigWriter.new(path).write!
139
+ end
140
+ Tmuxinator::ConfigWriter.write_aliases(aliases)
141
+ end
142
+
143
+ def doctor
144
+ print " cheking if tmux is installed ==> "
145
+ puts system("which tmux > /dev/null") ? "Yes" : "No"
146
+ print " cheking if $EDITOR is set ==> "
147
+ puts ENV['EDITOR'] ? "Yes" : "No"
148
+ print " cheking if $SHELL is set ==> "
149
+ puts ENV['SHELL'] ? "Yes" : "No"
150
+ puts %{
151
+ make sure you have this line in your ~/.bashrc file:
152
+
153
+ [[ -s $HOME/.tmuxinator/scripts/tmuxinator ]] && source $HOME/.tmuxinator/scripts/tmuxinator
154
+
155
+
156
+ }
157
+ end
158
+
159
+ def method_missing method, *args, &block
160
+ puts "There's no command called #{method} in tmuxinator"
161
+ usage
162
+ end
163
+
164
+ private #==============================
165
+
166
+ def root_dir
167
+ "#{ENV["HOME"]}/.tmuxinator/"
168
+ end
169
+
170
+ def sample_config
171
+ "#{File.dirname(__FILE__)}/assets/sample.yml"
172
+ end
173
+
174
+ def user_config
175
+ @config_to_copy || "#{ENV["HOME"]}/.tmuxinator/default.yml"
176
+ end
177
+
178
+ end
179
+
180
+ end
181
+ end
182
+
@@ -0,0 +1,102 @@
1
+ module Tmuxinator
2
+
3
+ class ConfigWriter
4
+ attr_accessor :file_name, :file_path, :project_name, :project_root, :rvm, :tabs, :pre
5
+
6
+ include Tmuxinator::Helper
7
+
8
+ def self.write_aliases aliases
9
+ File.open("#{ENV["HOME"]}/.tmuxinator/scripts/tmuxinator", 'w') {|f| f.write(aliases.join("\n")) }
10
+ end
11
+
12
+ def initialize this_full_path=nil
13
+ self.file_path = this_full_path if this_full_path
14
+ end
15
+
16
+ def file_path= full_path
17
+ @file_path = full_path
18
+ @file_name = File.basename full_path, '.yml'
19
+ process_config! if full_path && File.exist?(full_path)
20
+ end
21
+
22
+ def write!
23
+ raise "Unable to write with out a file_name defined" unless self.file_name
24
+ erb = ERB.new(IO.read(TMUX_TEMPLATE)).result(binding)
25
+ tmp = File.open(config_path, 'w') {|f| f.write(erb) }
26
+
27
+ "alias start_#{file_name}='$SHELL #{config_path}'"
28
+ end
29
+
30
+ def config_path
31
+ "#{root_dir}#{file_name}.tmux" if file_name
32
+ end
33
+
34
+ private
35
+
36
+ def root_dir
37
+ "#{ENV["HOME"]}/.tmuxinator/"
38
+ end
39
+
40
+ def process_config!
41
+ yaml = YAML.load(File.read(file_path))
42
+
43
+ exit!("Your configuration file should include some tabs.") if yaml["tabs"].nil?
44
+ exit!("Your configuration file didn't specify a 'project_root'") if yaml["project_root"].nil?
45
+ exit!("Your configuration file didn't specify a 'project_name'") if yaml["project_name"].nil?
46
+
47
+ @project_name = yaml["project_name"]
48
+ @project_root = yaml["project_root"]
49
+ @rvm = yaml["rvm"]
50
+ @pre = build_command(yaml["pre"])
51
+ @tabs = []
52
+
53
+ yaml["tabs"].each do |tab|
54
+ t = OpenStruct.new
55
+ t.name = tab.keys.first
56
+ value = tab.values.first
57
+
58
+ case value
59
+ when Hash
60
+ t.panes = (value["panes"] || ['']).map do |pane|
61
+ build_command(pane)
62
+ end
63
+ t.layout = value["layout"]
64
+ else
65
+ t.command = build_command(value)
66
+ end
67
+ @tabs << t
68
+ end
69
+ end
70
+
71
+ def parse_tabs tab_list
72
+ end
73
+
74
+ def write_alias stuff
75
+ File.open("#{root_dir}scripts/#{@filename}", 'w') {|f| f.write(stuff) }
76
+ end
77
+
78
+ def shell_escape str
79
+ "'#{str.to_s.gsub("'") { %('\'') }}'"
80
+ end
81
+ alias s shell_escape
82
+
83
+ def window(i)
84
+ "#{s @project_name}:#{i}"
85
+ end
86
+
87
+ def send_keys cmd, window_number
88
+ return '' unless cmd
89
+ "tmux send-keys -t #{window(window_number)} #{s cmd} C-m"
90
+ end
91
+
92
+ def build_command(value)
93
+ commands = [value].flatten.compact.reject { |c| c.strip.empty? }
94
+ if @rvm
95
+ commands.unshift "rvm use #{@rvm}"
96
+ end
97
+
98
+ commands.join ' && '
99
+ end
100
+ end
101
+
102
+ end
@@ -0,0 +1,19 @@
1
+ module Tmuxinator
2
+ module Helper
3
+
4
+ def exit!(msg)
5
+ puts msg
6
+ Kernel.exit(1)
7
+ end
8
+
9
+ def confirm!(msg)
10
+ puts msg
11
+ if %w(yes Yes YES y).include?(STDIN.gets.chop)
12
+ yield
13
+ else
14
+ exit! "Aborting."
15
+ end
16
+ end
17
+
18
+ end
19
+ end
@@ -0,0 +1,40 @@
1
+ module Tmuxinator
2
+
3
+ class ITermConfigWriter < ConfigWriter
4
+ attr_accessor :file_name, :file_path, :project_name, :project_root, :rvm, :tabs, :pre
5
+
6
+ include Tmuxinator::Helper
7
+
8
+ def self.write_aliases(aliases)
9
+ File.open("#{ENV["HOME"]}/.tmuxinator/scripts/tmuxinator", 'w') {|f| f.write(aliases.join("\n")) }
10
+ end
11
+
12
+ def initialize(this_full_path=nil)
13
+ self.file_path = this_full_path if this_full_path
14
+ end
15
+
16
+ def file_path= full_path
17
+ @file_path = full_path
18
+ @file_name = File.basename full_path, '.yml'
19
+ process_config! if full_path && File.exist?(full_path)
20
+ end
21
+
22
+ def write!
23
+ raise "Unable to write with out a file_name defined" unless file_name
24
+ erb = ERB.new(IO.read(ITERM_TEMPLATE)).result(binding)
25
+ tmp = File.open(config_path, 'w') {|f| f.write(erb) }
26
+
27
+ "alias iterm_#{file_name}='cat #{config_path} | osascript'"
28
+ end
29
+
30
+ def config_path
31
+ "#{root_dir}#{file_name}.AppleScript" if file_name
32
+ end
33
+
34
+ private
35
+
36
+ def write_alias(stuff)
37
+ File.open("#{root_dir}scripts/#{@filename}", 'w') {|f| f.write(stuff) }
38
+ end
39
+ end
40
+ end
@@ -0,0 +1,14 @@
1
+ $LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
2
+ $LOAD_PATH.unshift(File.dirname(__FILE__))
3
+ require 'rspec'
4
+ require 'tmuxinator'
5
+
6
+ # Requires supporting files with custom matchers and macros, etc,
7
+ # in ./support/ and its subdirectories.
8
+ Dir["#{File.dirname(__FILE__)}/support/**/*.rb"].each {|f| require f}
9
+
10
+ SAMPLE_CONFIG = File.join(File.dirname(__FILE__), '..', 'lib', 'tmuxinator', 'assets', 'sample.yml')
11
+
12
+ RSpec.configure do |config|
13
+
14
+ end
@@ -0,0 +1,52 @@
1
+ require File.expand_path(File.dirname(__FILE__) + '/spec_helper')
2
+
3
+ describe Tmuxinator::ConfigWriter do
4
+ context "With no defined filename" do
5
+ its(:file_path){ should be_nil }
6
+ its(:project_name){ should be_nil }
7
+ its(:project_root){ should be_nil }
8
+ its(:rvm){ should be_nil }
9
+ its(:tabs){ should be_nil }
10
+ its(:config_path){ should be_nil }
11
+ its(:pre){ should be_nil }
12
+ end
13
+
14
+ context "While Defining the filename on init" do
15
+ subject{ Tmuxinator::ConfigWriter.new(SAMPLE_CONFIG) }
16
+ its(:file_path){ should eql SAMPLE_CONFIG }
17
+ its(:file_name){ should eql "sample" }
18
+ end
19
+
20
+ context "After filename has been defined" do
21
+ before do
22
+ subject.file_path = SAMPLE_CONFIG
23
+ end
24
+
25
+ its(:file_path){ should eql SAMPLE_CONFIG }
26
+ its(:file_name){ should eql File.basename(SAMPLE_CONFIG, '.yml')}
27
+ its(:project_name){ should eql 'Tmuxinator' }
28
+ its(:project_root){ should eql '~/code/rails_project' }
29
+ its(:rvm){ should eql '1.9.2@rails_project' }
30
+ its(:tabs){ should be_an Array }
31
+ its(:pre){ should eql 'sudo /etc/rc.d/mysqld start' }
32
+
33
+ let(:first_tab){ subject.tabs[0] }
34
+
35
+ specify{ first_tab.should be_an OpenStruct }
36
+ specify{ first_tab.name.should eql "editor" }
37
+ specify{ first_tab.layout.should eql "main-vertical" }
38
+ specify{ first_tab.panes.should be_an Array }
39
+
40
+ it "should prepend each pane with the rvm string" do
41
+ first_tab.panes.map{|p| p.split(/ && /)[0] }.should eql ["rvm use 1.9.2@rails_project"] * 3
42
+ end
43
+
44
+ it "should append each pane with the command string" do
45
+ first_tab.panes.map{|p| p.split(/ && /)[1] }.should eql ["vim", nil, "top"]
46
+ end
47
+
48
+ let(:second_tab){ subject.tabs[1] }
49
+ specify{ second_tab.name.should eql "shell" }
50
+ specify{ second_tab.command.should eql "rvm use 1.9.2@rails_project && git pull"}
51
+ end
52
+ end
metadata ADDED
@@ -0,0 +1,121 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: dkastner-tmuxinator
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.4.0
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - Derek Kastner
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2011-06-20 00:00:00.000000000Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: rspec
16
+ requirement: &2154588240 !ruby/object:Gem::Requirement
17
+ none: false
18
+ requirements:
19
+ - - ~>
20
+ - !ruby/object:Gem::Version
21
+ version: 2.1.0
22
+ type: :development
23
+ prerelease: false
24
+ version_requirements: *2154588240
25
+ - !ruby/object:Gem::Dependency
26
+ name: bundler
27
+ requirement: &2154587740 !ruby/object:Gem::Requirement
28
+ none: false
29
+ requirements:
30
+ - - ~>
31
+ - !ruby/object:Gem::Version
32
+ version: 1.0.0
33
+ type: :development
34
+ prerelease: false
35
+ version_requirements: *2154587740
36
+ - !ruby/object:Gem::Dependency
37
+ name: jeweler
38
+ requirement: &2154587240 !ruby/object:Gem::Requirement
39
+ none: false
40
+ requirements:
41
+ - - ~>
42
+ - !ruby/object:Gem::Version
43
+ version: 1.5.1
44
+ type: :development
45
+ prerelease: false
46
+ version_requirements: *2154587240
47
+ - !ruby/object:Gem::Dependency
48
+ name: rcov
49
+ requirement: &2154586740 !ruby/object:Gem::Requirement
50
+ none: false
51
+ requirements:
52
+ - - ! '>='
53
+ - !ruby/object:Gem::Version
54
+ version: '0'
55
+ type: :development
56
+ prerelease: false
57
+ version_requirements: *2154586740
58
+ description: Create and manage complex tmux and iTerm sessions easily.
59
+ email: dkastner@gmail.com
60
+ executables:
61
+ - tmuxinator
62
+ extensions: []
63
+ extra_rdoc_files:
64
+ - LICENSE.txt
65
+ - README.md
66
+ files:
67
+ - .document
68
+ - .rspec
69
+ - Gemfile
70
+ - Gemfile.lock
71
+ - LICENSE.txt
72
+ - README.md
73
+ - Rakefile
74
+ - VERSION
75
+ - bin/tmuxinator
76
+ - lib/tmuxinator.rb
77
+ - lib/tmuxinator/assets/iterm.AppleScript
78
+ - lib/tmuxinator/assets/sample.yml
79
+ - lib/tmuxinator/assets/tmux_config.tmux
80
+ - lib/tmuxinator/cli.rb
81
+ - lib/tmuxinator/config_writer.rb
82
+ - lib/tmuxinator/iterm_config_writer.rb
83
+ - lib/tmuxinator/helper.rb
84
+ - spec/spec_helper.rb
85
+ - spec/tmuxinator_spec.rb
86
+ - dkastner-tmuxinator.gemspec
87
+ homepage: http://github.com/dkastner/tmuxinator
88
+ licenses:
89
+ - MIT
90
+ post_install_message: ! "\n __________________________________________________________\n
91
+ \ ..........................................................\n\n Thank you for
92
+ installing tmuxinator\n Please be sure to to drop a line in your ~/.bashrc file,
93
+ similar \n to RVM if you've used that before:\n\n [[ -s $HOME/.tmuxinator/scripts/tmuxinator
94
+ ]] && source $HOME/.tmuxinator/scripts/tmuxinator\n \n also ensure that you've
95
+ set these variables in your ENV:\n \n $EDITOR, $SHELL\n \n you can run `tmuxinator
96
+ doctor` to make sure everything is set.\n happy tmuxing with tmuxinator!\n\n ..........................................................\n
97
+ \ __________________________________________________________\n \n "
98
+ rdoc_options: []
99
+ require_paths:
100
+ - lib
101
+ required_ruby_version: !ruby/object:Gem::Requirement
102
+ none: false
103
+ requirements:
104
+ - - ! '>='
105
+ - !ruby/object:Gem::Version
106
+ version: '0'
107
+ required_rubygems_version: !ruby/object:Gem::Requirement
108
+ none: false
109
+ requirements:
110
+ - - ! '>='
111
+ - !ruby/object:Gem::Version
112
+ version: '0'
113
+ requirements: []
114
+ rubyforge_project:
115
+ rubygems_version: 1.8.5
116
+ signing_key:
117
+ specification_version: 3
118
+ summary: Create and manage complex tmux sessions easily.
119
+ test_files:
120
+ - spec/spec_helper.rb
121
+ - spec/tmuxinator_spec.rb