tmuxinator 0.5.0 → 0.6.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (46) hide show
  1. checksums.yaml +7 -0
  2. data/.gitignore +17 -0
  3. data/.rspec +1 -1
  4. data/.travis.yml +5 -0
  5. data/CHANGELOG.md +36 -0
  6. data/CONTRIBUTING.md +29 -0
  7. data/Gemfile +4 -7
  8. data/{LICENSE.txt → LICENSE} +1 -1
  9. data/README.md +128 -118
  10. data/Rakefile +1 -72
  11. data/bin/mux +8 -3
  12. data/bin/tmuxinator +8 -3
  13. data/completion/tmuxinator.bash +18 -0
  14. data/completion/tmuxinator.zsh +20 -0
  15. data/lib/tmuxinator.rb +13 -7
  16. data/lib/tmuxinator/assets/sample.yml +24 -11
  17. data/lib/tmuxinator/assets/template.erb +47 -0
  18. data/lib/tmuxinator/cli.rb +121 -145
  19. data/lib/tmuxinator/config.rb +92 -0
  20. data/lib/tmuxinator/deprecations.rb +19 -0
  21. data/lib/tmuxinator/pane.rb +36 -0
  22. data/lib/tmuxinator/project.rb +142 -0
  23. data/lib/tmuxinator/util.rb +14 -0
  24. data/lib/tmuxinator/version.rb +3 -0
  25. data/lib/tmuxinator/window.rb +76 -0
  26. data/spec/factories/projects.rb +17 -0
  27. data/spec/fixtures/sample.deprecations.yml +35 -0
  28. data/spec/fixtures/sample.yml +35 -0
  29. data/spec/lib/tmuxinator/cli_spec.rb +230 -0
  30. data/spec/lib/tmuxinator/config_spec.rb +121 -0
  31. data/spec/lib/tmuxinator/pane_spec.rb +7 -0
  32. data/spec/lib/tmuxinator/project_spec.rb +209 -0
  33. data/spec/lib/tmuxinator/util_spec.rb +4 -0
  34. data/spec/lib/tmuxinator/window_spec.rb +62 -0
  35. data/spec/spec_helper.rb +28 -8
  36. data/tmuxinator.gemspec +47 -65
  37. metadata +186 -62
  38. data/.document +0 -5
  39. data/Gemfile.lock +0 -28
  40. data/TODO +0 -4
  41. data/VERSION +0 -1
  42. data/bin/tmuxinator_completion +0 -29
  43. data/lib/tmuxinator/assets/tmux_config.tmux +0 -37
  44. data/lib/tmuxinator/config_writer.rb +0 -104
  45. data/lib/tmuxinator/helper.rb +0 -19
  46. data/spec/tmuxinator_spec.rb +0 -54
@@ -0,0 +1,35 @@
1
+ # ~/.tmuxinator/sample.yml
2
+ # you can make as many tabs as you wish...
3
+
4
+ name: sample
5
+ root: ~/test
6
+ socket_name: foo # Remove to use default socket
7
+ pre: sudo /etc/rc.d/mysqld start # Runs before everything
8
+ pre_window: rbenv shell 2.0.0-p247 # Runs in each tab and pane
9
+ tmux_options: -v -2 # Pass arguments to tmux
10
+ windows:
11
+ - editor:
12
+ pre:
13
+ - echo "I get run in each pane, before each pane command!"
14
+ -
15
+ layout: main-vertical
16
+ panes:
17
+ - vim
18
+ - #empty, will just run plain bash
19
+ - top
20
+ - shell: git pull
21
+ - guard:
22
+ layout: tiled
23
+ pre:
24
+ - echo "I get run in each pane."
25
+ - echo "Before each pane command!"
26
+ panes:
27
+ -
28
+ - #empty, will just run plain bash
29
+ -
30
+ - database: bundle exec rails db
31
+ - server: bundle exec rails s
32
+ - logs: tail -f log/development.log
33
+ - console: bundle exec rails c
34
+ - capistrano:
35
+ - server: ssh user@example.com
@@ -0,0 +1,230 @@
1
+ require "spec_helper"
2
+ describe Tmuxinator::Cli do
3
+ let(:cli) { Tmuxinator::Cli }
4
+
5
+ before do
6
+ ARGV.clear
7
+ Kernel.stub(:system)
8
+ FileUtils.stub(:copy_file)
9
+ FileUtils.stub(:rm)
10
+ FileUtils.stub(:remove_dir)
11
+ end
12
+
13
+ context "no arguments" do
14
+ it "runs without error" do
15
+ _, err = capture_io { cli.start }
16
+ expect(err).to be_empty
17
+ end
18
+ end
19
+
20
+ describe "#completions" do
21
+ before do
22
+ ARGV.replace(["completions", "start"])
23
+ Tmuxinator::Config.stub(:configs => ["test.yml"])
24
+ end
25
+
26
+ it "gets completions" do
27
+ out, _ = capture_io { cli.start }
28
+ expect(out).to include("test.yml")
29
+ end
30
+ end
31
+
32
+ describe "#commands" do
33
+ before do
34
+ ARGV.replace(["commands"])
35
+ end
36
+
37
+ it "lists the commands" do
38
+ out, _ = capture_io { cli.start }
39
+ expect(out).to eq "#{%w(commands copy debug delete doctor help implode list start version).join("\n")}\n"
40
+ end
41
+ end
42
+
43
+ describe "#start" do
44
+ before do
45
+ ARGV.replace(["start", "foo"])
46
+ Tmuxinator::Config.stub(:validate => project)
47
+ Kernel.stub(:exec)
48
+ end
49
+
50
+ context "no deprecations" do
51
+ let(:project) { FactoryGirl.build(:project) }
52
+
53
+ it "starts the project" do
54
+ expect(Kernel).to receive(:exec)
55
+ capture_io { cli.start }
56
+ end
57
+ end
58
+
59
+ context "deprecations" do
60
+ before do
61
+ $stdin.stub(:getc => "y")
62
+ end
63
+
64
+ let(:project) { FactoryGirl.build(:project_with_deprecations) }
65
+
66
+ it "prints the deprecations" do
67
+ out, _ = capture_io { cli.start }
68
+ expect(out).to include "DEPRECATION"
69
+ end
70
+ end
71
+ end
72
+
73
+ describe "#new" do
74
+ let(:file) { StringIO.new }
75
+
76
+ before do
77
+ ARGV.replace(["new", "test"])
78
+ File.stub(:open) { |&block| block.yield file }
79
+ end
80
+
81
+ context "existing project doesn't exist" do
82
+ before do
83
+ Tmuxinator::Config.stub(:exists? => false)
84
+ end
85
+
86
+ it "creates a new tmuxinator project file" do
87
+ capture_io { cli.start }
88
+ expect(file.string).to_not be_empty
89
+ end
90
+ end
91
+
92
+ context "files exists" do
93
+ before do
94
+ File.stub(:exists? => true)
95
+ end
96
+
97
+ it "just opens the file" do
98
+ expect(Kernel).to receive(:system)
99
+ capture_io { cli.start }
100
+ end
101
+ end
102
+ end
103
+
104
+ describe "#copy" do
105
+ before do
106
+ ARGV.replace(["copy", "foo", "bar"])
107
+ Tmuxinator::Config.stub(:exists?) { true }
108
+ end
109
+
110
+ context "new project already exists" do
111
+ before do
112
+ $stdin.stub(:gets => "y")
113
+ end
114
+
115
+ it "prompts user to confirm overwrite" do
116
+ expect(FileUtils).to receive(:rm)
117
+ capture_io { cli.start }
118
+ end
119
+
120
+ it "copies the config" do
121
+ expect(FileUtils).to receive(:copy_file)
122
+ capture_io { cli.start }
123
+ end
124
+ end
125
+
126
+ context "existing project doens't exist" do
127
+ before do
128
+ Tmuxinator::Config.stub(:exists?) { false }
129
+ end
130
+
131
+ it "exit with error code" do
132
+ expect { capture_io { cli.start } }.to raise_error SystemExit
133
+ end
134
+ end
135
+ end
136
+
137
+ describe "#debug" do
138
+ let(:project) { FactoryGirl.build(:project) }
139
+
140
+ before do
141
+ ARGV.replace(["debug", "foo"])
142
+ Tmuxinator::Config.stub(:validate => project)
143
+ end
144
+
145
+ it "renders the project" do
146
+ expect(project).to receive(:render)
147
+ capture_io { cli.start }
148
+ end
149
+ end
150
+
151
+ describe "#delete" do
152
+ before do
153
+ ARGV.replace(["delete", "foo"])
154
+ end
155
+
156
+ context "project exists" do
157
+ before do
158
+ $stdin.stub(:gets => "y")
159
+ Tmuxinator::Config.stub(:exists?) { true }
160
+ end
161
+
162
+ it "confirms deletion" do
163
+ capture_io { cli.start }
164
+ end
165
+
166
+ it "deletes the project" do
167
+ expect(FileUtils).to receive(:rm)
168
+ capture_io { cli.start }
169
+ end
170
+ end
171
+
172
+ context "project doesn't exist" do
173
+ it "exits with error message" do
174
+ expect { capture_io { cli.start } }.to raise_error SystemExit
175
+ end
176
+ end
177
+ end
178
+
179
+ describe "#implode" do
180
+ before do
181
+ ARGV.replace(["implode"])
182
+ $stdin.stub(:gets => "y")
183
+ end
184
+
185
+ it "confirms deletion of all projects" do
186
+ expect($stdin).to receive(:gets).and_return("y")
187
+ capture_io { cli.start }
188
+ end
189
+
190
+ it "deletes all projects" do
191
+ expect(FileUtils).to receive(:remove_dir)
192
+ capture_io { cli.start }
193
+ end
194
+ end
195
+
196
+ describe "#list" do
197
+ before do
198
+ ARGV.replace(["list"])
199
+ Dir.stub(:[] => ["/path/to/project.yml"])
200
+ end
201
+
202
+ it "lists all projects" do
203
+ expect { capture_io { cli.start } }.to_not raise_error
204
+ end
205
+ end
206
+
207
+ describe "#version" do
208
+ before do
209
+ ARGV.replace(["version"])
210
+ end
211
+
212
+ it "prints the current version" do
213
+ out, _ = capture_io { cli.start }
214
+ expect(out).to eq "tmuxinator #{Tmuxinator::VERSION}\n"
215
+ end
216
+ end
217
+
218
+ describe "#doctor" do
219
+ before do
220
+ ARGV.replace(["doctor"])
221
+ end
222
+
223
+ it "checks requirements" do
224
+ Tmuxinator::Config.should_receive(:installed?)
225
+ Tmuxinator::Config.should_receive(:editor?)
226
+ Tmuxinator::Config.should_receive(:shell?)
227
+ capture_io { cli.start }
228
+ end
229
+ end
230
+ end
@@ -0,0 +1,121 @@
1
+ require "spec_helper"
2
+
3
+ describe Tmuxinator::Config do
4
+ describe "#root" do
5
+ it "is ~/.tmuxintaor" do
6
+ expect(Tmuxinator::Config.root).to eq "#{ENV["HOME"]}/.tmuxinator"
7
+ end
8
+ end
9
+
10
+ describe "#sample" do
11
+ it "gets the path of the sample project" do
12
+ expect(Tmuxinator::Config.sample).to include("sample.yml")
13
+ end
14
+ end
15
+
16
+ describe "#default" do
17
+ it "gets the path of the default config" do
18
+ expect(Tmuxinator::Config.default).to include("default.yml")
19
+ end
20
+ end
21
+
22
+ describe "#configs" do
23
+ before do
24
+ Dir.stub(:[] => ["test.yml"])
25
+ end
26
+
27
+ it "gets a list of all projects" do
28
+ expect(Tmuxinator::Config.configs).to include("test")
29
+ end
30
+ end
31
+
32
+ describe "#installed?" do
33
+ context "tmux is installed" do
34
+ before do
35
+ Kernel.stub(:system) { true }
36
+ end
37
+
38
+ it "returns true" do
39
+ expect(Tmuxinator::Config.installed?).to be_true
40
+ end
41
+ end
42
+
43
+ context "tmux is not installed" do
44
+ before do
45
+ Kernel.stub(:system) { false }
46
+ end
47
+
48
+ it "returns true" do
49
+ expect(Tmuxinator::Config.installed?).to be_false
50
+ end
51
+ end
52
+ end
53
+
54
+ describe "#editor?" do
55
+ context "$EDITOR is set" do
56
+ before do
57
+ ENV.stub(:[]).with("EDITOR") { "vim" }
58
+ end
59
+
60
+ it "returns true" do
61
+ expect(Tmuxinator::Config.editor?).to be_true
62
+ end
63
+ end
64
+
65
+ context "$EDITOR is not set" do
66
+ before do
67
+ ENV.stub(:[]).with("EDITOR") { nil }
68
+ end
69
+
70
+ it "returns false" do
71
+ expect(Tmuxinator::Config.editor?).to be_false
72
+ end
73
+ end
74
+ end
75
+
76
+ describe "#shell?" do
77
+ context "$SHELL is set" do
78
+ before do
79
+ ENV.stub(:[]).with("SHELL") { "vim" }
80
+ end
81
+
82
+ it "returns true" do
83
+ expect(Tmuxinator::Config.shell?).to be_true
84
+ end
85
+ end
86
+
87
+ context "$SHELL is not set" do
88
+ before do
89
+ ENV.stub(:[]).with("SHELL") { nil }
90
+ end
91
+
92
+ it "returns false" do
93
+ expect(Tmuxinator::Config.shell?).to be_false
94
+ end
95
+ end
96
+ end
97
+
98
+ describe "#exists?" do
99
+ before do
100
+ File.stub(:exists? => true)
101
+ Tmuxinator::Config.stub(:project => "")
102
+ end
103
+
104
+ it "checks if the given project exists" do
105
+ expect(Tmuxinator::Config.exists?("test")).to be_true
106
+ end
107
+ end
108
+
109
+ describe "#project" do
110
+ before do
111
+ Dir.stub(:glob => ["#{Tmuxinator::Config.root}/test.yml"])
112
+ end
113
+
114
+
115
+ let(:root) { Tmuxinator::Config.root }
116
+
117
+ it "gets the project as path to the yml file" do
118
+ expect(Tmuxinator::Config.project("test")).to eq "#{root}/test.yml"
119
+ end
120
+ end
121
+ end
@@ -0,0 +1,7 @@
1
+ require "spec_helper"
2
+
3
+ describe Tmuxinator::Pane do
4
+ it "creates an instance" do
5
+ expect(Tmuxinator::Pane.new("vim", 0, nil, nil)).to be_a(Tmuxinator::Pane)
6
+ end
7
+ end
@@ -0,0 +1,209 @@
1
+ require "spec_helper"
2
+
3
+ describe Tmuxinator::Project do
4
+ let(:project) { FactoryGirl.build(:project) }
5
+ let(:project_with_deprecations) { FactoryGirl.build(:project_with_deprecations) }
6
+
7
+ describe "#initialize" do
8
+ context "valid yaml" do
9
+ it "creates an instance" do
10
+ expect(project).to be_a(Tmuxinator::Project)
11
+ end
12
+ end
13
+ end
14
+
15
+ describe "#render" do
16
+ it "renders the tmux config" do
17
+ expect(project.render).to_not be_empty
18
+ end
19
+ end
20
+
21
+ describe "#windows" do
22
+ context "without deprecations" do
23
+ it "gets the list of windows" do
24
+ expect(project.windows).to_not be_empty
25
+ end
26
+ end
27
+
28
+ context "with deprecations" do
29
+ it "still gets the list of windows" do
30
+ expect(project_with_deprecations.windows).to_not be_empty
31
+ end
32
+ end
33
+ end
34
+
35
+ describe "#root" do
36
+ context "without deprecations" do
37
+ it "gets the root" do
38
+ expect(project.root).to eq "~/test"
39
+ end
40
+ end
41
+
42
+ context "with deprecations" do
43
+ it "still gets the root" do
44
+ expect(project_with_deprecations.root).to eq "~/test"
45
+ end
46
+ end
47
+ end
48
+
49
+ describe "#name" do
50
+ context "without deprecations" do
51
+ it "gets the name" do
52
+ expect(project.name).to eq "sample"
53
+ end
54
+ end
55
+
56
+ context "with deprecations" do
57
+ it "still gets the name" do
58
+ expect(project_with_deprecations.name).to eq "sample"
59
+ end
60
+ end
61
+ end
62
+
63
+ describe "#pre_window" do
64
+ it "gets the pre_window command" do
65
+ expect(project.pre_window).to eq "rbenv shell 2.0.0-p247"
66
+ end
67
+
68
+ context "with deprecations" do
69
+ context "rbenv option is present" do
70
+ before do
71
+ project.stub(:rbenv? => true)
72
+ project.stub_chain(:yaml, :[]).and_return("2.0.0-p247")
73
+ end
74
+
75
+ it "still gets the correct pre_window command" do
76
+ expect(project.pre_window).to eq "rbenv shell 2.0.0-p247"
77
+ end
78
+ end
79
+
80
+ context "rvm option is present" do
81
+ before do
82
+ project.stub(:rbenv? => false)
83
+ project.stub_chain(:yaml, :[]).and_return("ruby-2.0.0-p247")
84
+ end
85
+
86
+ it "still gets the correct pre_window command" do
87
+ expect(project.pre_window).to eq "rvm use ruby-2.0.0-p247"
88
+ end
89
+ end
90
+
91
+ context "pre_tab is present" do
92
+ before do
93
+ project.stub(:rbenv? => false)
94
+ project.stub(:pre_tab? => true)
95
+ end
96
+
97
+ it "still gets the correct pre_window command" do
98
+ expect(project.pre_window).to be_nil
99
+ end
100
+ end
101
+ end
102
+ end
103
+
104
+ describe "#socket" do
105
+ context "socket path is present" do
106
+ before do
107
+ project.stub(:socket_path => "/tmp")
108
+ end
109
+
110
+ it "gets the socket path" do
111
+ expect(project.socket).to eq " -S /tmp"
112
+ end
113
+ end
114
+ end
115
+
116
+ describe "#tmux_options" do
117
+ context "no tmux options" do
118
+ before do
119
+ project.stub(:tmux_options? => false)
120
+ end
121
+
122
+ it "returns nothing" do
123
+ expect(project.tmux_options).to eq ""
124
+ end
125
+ end
126
+
127
+ context "with deprecations" do
128
+ before do
129
+ project_with_deprecations.stub(:cli_args? => true)
130
+ end
131
+
132
+ it "still gets the tmux options" do
133
+ expect(project_with_deprecations.tmux_options).to eq " -v -2"
134
+ end
135
+ end
136
+ end
137
+
138
+ describe "#window" do
139
+ it "gets the window and index for tmux" do
140
+ expect(project.window(1)).to eq "sample:1"
141
+ end
142
+ end
143
+
144
+ describe "#name?" do
145
+ context "name is present" do
146
+ it "returns true" do
147
+ expect(project.name?).to be_true
148
+ end
149
+ end
150
+ end
151
+
152
+ describe "#windows?" do
153
+ context "windows are present" do
154
+ it "returns true" do
155
+ expect(project.windows?).to be_true
156
+ end
157
+ end
158
+ end
159
+
160
+ describe "#root?" do
161
+ context "root are present" do
162
+ it "returns true" do
163
+ expect(project.root?).to be_true
164
+ end
165
+ end
166
+ end
167
+
168
+ describe "#send_keys" do
169
+ context "no command for window" do
170
+ it "returns empty string" do
171
+ expect(project.send_keys("", 1)).to be_empty
172
+ end
173
+ end
174
+
175
+ context "command for window is not empty" do
176
+ it "returns the tmux command" do
177
+ expect(project.send_keys("vim", 1)).to eq "tmux -v -2 -L foo send-keys -t sample:1 vim C-m"
178
+ end
179
+ end
180
+ end
181
+
182
+ describe "#send_pane_command" do
183
+ context "no command for pane" do
184
+ it "returns empty string" do
185
+ expect(project.send_pane_command("", 0, 0)).to be_empty
186
+ end
187
+ end
188
+
189
+ context "command for pane is not empty" do
190
+ it "returns the tmux command" do
191
+ expect(project.send_pane_command("vim", 1, 0)).to eq "tmux -v -2 -L foo send-keys -t sample:1 vim C-m"
192
+ end
193
+ end
194
+ end
195
+
196
+ describe "#deprecations" do
197
+ context "without deprecations" do
198
+ it "is empty" do
199
+ expect(project.deprecations).to be_empty
200
+ end
201
+ end
202
+
203
+ context "with deprecations" do
204
+ it "is not empty" do
205
+ expect(project_with_deprecations.deprecations).to_not be_empty
206
+ end
207
+ end
208
+ end
209
+ end