teamocil 0.2.2 → 0.3.1

Sign up to get free protection for your applications and to get access to all the features.
data/.travis.yml ADDED
@@ -0,0 +1,2 @@
1
+ rvm: 1.9.2
2
+ script: "bundle exec rake spec"
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- teamocil (0.2.2)
4
+ teamocil (0.3.1)
5
5
 
6
6
  GEM
7
7
  remote: http://rubygems.org/
data/README.md CHANGED
@@ -2,13 +2,17 @@
2
2
 
3
3
  Teamocil is a simple tool used to automatically create sessions, windows and splits in [tmux](http://tmux.sourceforge.net/) with YAML files.
4
4
 
5
+ [![Build Status](https://secure.travis-ci.org/remiprev/teamocil.png)](http://travis-ci.org/remiprev/teamocil)
6
+
5
7
  ## Usage
6
8
 
7
- $ gem install teamocil
8
- $ mkdir ~/.teamocil
9
- $ teamocil --edit sample
10
- $ tmux
11
- $ teamocil sample
9
+ ```bash
10
+ $ gem install teamocil
11
+ $ mkdir ~/.teamocil
12
+ $ teamocil --edit sample
13
+ $ tmux
14
+ $ teamocil sample
15
+ ```
12
16
 
13
17
  ## Options
14
18
 
@@ -30,10 +34,12 @@ You can wrap your entire layout file in a `session` and Teamocil will rename the
30
34
 
31
35
  #### Example
32
36
 
33
- session:
34
- name: my-awesome-session
35
- windows:
36
- [windows list]
37
+ ```yaml
38
+ session:
39
+ name: "my-awesome-session"
40
+ windows:
41
+ [windows list]
42
+ ```
37
43
 
38
44
  ### Windows
39
45
 
@@ -49,27 +55,27 @@ If you are not using a top-level `session` key, then the first key of your layou
49
55
 
50
56
  #### Example
51
57
 
52
- windows:
53
- - name: my-first-window
54
- options:
55
- synchronize-panes: true
56
- root: ~/Projects/foo-www
57
- filters:
58
- before:
59
- - "echo 'Let’s use ruby-1.9.2 for each split in this window.'"
60
- - "rvm use 1.9.2"
61
- splits:
62
- [splits list]
63
- - name: my-second-window
64
- root: ~/Projects/foo-api
65
- filters:
66
- after: "rvm use 1.9.2"
67
- splits:
68
- [splits list]
69
- - name: my-third-window
70
- root: ~/Projects/foo-daemons
71
- splits:
72
- [splits list]
58
+ ```yaml
59
+ windows:
60
+ - name: "my-first-window"
61
+ options:
62
+ synchronize-panes: true
63
+ root: "~/Projects/foo-www"
64
+ filters:
65
+ before:
66
+ - "echo 'Let’s use ruby-1.9.2 for each split in this window.'"
67
+ - "rvm use 1.9.2"
68
+ splits:
69
+ [splits list]
70
+ - name: "my-second-window"
71
+ root: "~/Projects/foo-api"
72
+ splits:
73
+ [splits list]
74
+ - name: "my-third-window"
75
+ root: "~/Projects/foo-daemons"
76
+ splits:
77
+ [splits list]
78
+ ```
73
79
 
74
80
  ### Splits
75
81
 
@@ -84,20 +90,22 @@ Every window must define an array of splits that will be created within it. A ve
84
90
 
85
91
  #### Example
86
92
 
87
- windows:
88
- - name: my-first-window
89
- root: ~/Projects/foo-www
90
- filters:
91
- before: "rvm use 1.9.2"
92
- after: "echo 'I am done initializing this split.'"
93
- splits:
94
- - cmd: "git status"
95
- - cmd: "bundle exec rails server --port 4000"
96
- width: 50
97
- - cmd:
98
- - sudo service memcached start
99
- - sudo service mongodb start
100
- height: 50
93
+ ```yaml
94
+ windows:
95
+ - name: "my-first-window"
96
+ root: "~/Projects/foo-www"
97
+ filters:
98
+ before: "rvm use 1.9.2"
99
+ after: "echo 'I am done initializing this split.'"
100
+ splits:
101
+ - cmd: "git status"
102
+ - cmd: "bundle exec rails server --port 4000"
103
+ width: 50
104
+ - cmd:
105
+ - "sudo service memcached start"
106
+ - "sudo service mongodb start"
107
+ height: 50
108
+ ```
101
109
 
102
110
  ## Layout examples
103
111
 
@@ -107,15 +115,16 @@ See more example files in the `examples` directory.
107
115
 
108
116
  #### Content of `~/.teamocil/sample-1.yml`
109
117
 
110
- windows:
111
- - name: sample-two-splits
112
- root: ~/Code/sample/www
113
- splits:
114
- - cmd:
115
- - pwd
116
- - ls -la
117
- - cmd: rails server --port 3000
118
- width: 50
118
+ ```yaml
119
+ windows:
120
+ - name: "sample-two-splits"
121
+ root: "~/Code/sample/www"
122
+ splits:
123
+ - cmd: ["pwd", "ls -la"]
124
+ - cmd: "rails server --port 3000"
125
+ width: 50
126
+ ```
127
+
119
128
 
120
129
  #### Result of `$ teamocil sample-1`
121
130
 
@@ -135,19 +144,21 @@ See more example files in the `examples` directory.
135
144
 
136
145
  #### Content of `~/.teamocil/sample-2.yml`
137
146
 
138
- windows:
139
- - name: sample-four-splits
140
- root: ~/Code/sample/www
141
- splits:
142
- - cmd: pwd
143
- - cmd: pwd
144
- width: 50
145
- - cmd: pwd
146
- height: 50
147
- target: bottom-right
148
- - cmd: pwd
149
- height: 50
150
- target: bottom-left
147
+ ```yaml
148
+ windows:
149
+ - name: "sample-four-splits"
150
+ root: "~/Code/sample/www"
151
+ splits:
152
+ - cmd: "pwd"
153
+ - cmd: "pwd"
154
+ width: 50
155
+ - cmd: "pwd"
156
+ height: 50
157
+ target: "bottom-right"
158
+ - cmd: "pwd"
159
+ height: 50
160
+ target: "bottom-left"
161
+ ```
151
162
 
152
163
  #### Result of `$ teamocil sample-2`
153
164
 
@@ -169,7 +180,9 @@ See more example files in the `examples` directory.
169
180
 
170
181
  To get autocompletion when typing `teamocil <Tab>` in a zsh session, add this line to your `~/.zshrc` file:
171
182
 
172
- compctl -g '~/.teamocil/*(:t:r)' teamocil
183
+ ```zsh
184
+ compctl -g '~/.teamocil/*(:t:r)' teamocil
185
+ ```
173
186
 
174
187
  ## Todo list
175
188
 
data/lib/teamocil/cli.rb CHANGED
@@ -5,6 +5,8 @@ module Teamocil
5
5
  # This class handles interaction with the `tmux` utility.
6
6
  class CLI
7
7
 
8
+ attr_accessor :layout, :layouts
9
+
8
10
  # Initialize a new run of `tmux`
9
11
  #
10
12
  # @param argv [Hash] the command line parameters hash (usually `ARGV`).
@@ -12,11 +14,18 @@ module Teamocil
12
14
  def initialize(argv, env) # {{{
13
15
  bail "You must be in a tmux session to use teamocil" unless env["TMUX"]
14
16
 
15
- parse_options!
17
+ parse_options! argv
18
+ layout_path = File.join("#{env["HOME"]}", ".teamocil")
19
+
20
+ if @options.include?(:list)
21
+ @layouts = get_layouts(layout_path)
22
+ return print_layouts
23
+ end
24
+
16
25
  if @options.include?(:layout)
17
- file = options[:layout]
26
+ file = @options[:layout]
18
27
  else
19
- file = ::File.join("#{env["HOME"]}/.teamocil", "#{argv[0]}.yml")
28
+ file = ::File.join(layout_path, "#{argv[0]}.yml")
20
29
  end
21
30
 
22
31
  if @options[:edit]
@@ -25,14 +34,14 @@ module Teamocil
25
34
  else
26
35
  bail "There is no file \"#{file}\"" unless File.exists?(file)
27
36
  parsed_layout = YAML.load_file(file)
28
- layout = Teamocil::Layout.new(parsed_layout, @options)
29
- layout.compile!
30
- layout.execute_commands(layout.generate_commands)
37
+ @layout = Teamocil::Layout.new(parsed_layout, @options)
38
+ @layout.compile!
39
+ @layout.execute_commands(@layout.generate_commands)
31
40
  end
32
41
  end # }}}
33
42
 
34
43
  # Parse the command line options
35
- def parse_options! # {{{
44
+ def parse_options!(args) # {{{
36
45
  @options = {}
37
46
  opts = ::OptionParser.new do |opts|
38
47
  opts.banner = "Usage: teamocil [options] <layout>
@@ -47,19 +56,36 @@ module Teamocil
47
56
  @options[:edit] = true
48
57
  end
49
58
 
50
- opts.on("--layout [LAYOUT]", "Use a specific layout file, instead of ~/.teamocil/<layout>.yml") do |layout|
59
+ opts.on("--layout [LAYOUT]", "Use a specific layout file, instead of `~/.teamocil/<layout>.yml`") do |layout|
51
60
  @options[:layout] = layout
52
61
  end
53
62
 
63
+ opts.on("--list", "List all available layouts in `~/.teamocil/`") do
64
+ @options[:list] = true
65
+ end
66
+
54
67
  end
55
- opts.parse!
68
+ opts.parse! args
69
+ end # }}}
70
+
71
+ # Return an array of available layouts
72
+ #
73
+ # @param path [String] the path used to look for layouts
74
+ def get_layouts(path) # {{{
75
+ Dir.glob(File.join(path, "*.yml")).map { |file| File.basename(file).gsub(/\..+$/, "") }.sort
76
+ end # }}}
77
+
78
+ # Print each layout on a single line
79
+ def print_layouts # {{{
80
+ STDOUT.puts @layouts.join("\n")
81
+ exit 0
56
82
  end # }}}
57
83
 
58
84
  # Print an error message and exit the utility
59
85
  #
60
86
  # @param msg [Mixed] something to print before exiting.
61
87
  def bail(msg) # {{{
62
- puts "[teamocil] #{msg}"
88
+ STDERR.puts "[teamocil] #{msg}"
63
89
  exit 1
64
90
  end # }}}
65
91
 
@@ -2,6 +2,7 @@ module Teamocil
2
2
 
3
3
  # This class act as a wrapper around a tmux YAML layout file
4
4
  class Layout
5
+ attr_reader :session
5
6
 
6
7
  # This class represents a session within tmux
7
8
  class Session
data/lib/teamocil.rb CHANGED
@@ -1,5 +1,5 @@
1
1
  module Teamocil
2
- VERSION = "0.2.2"
2
+ VERSION = "0.3.1"
3
3
  autoload :Layout, "teamocil/layout"
4
4
  autoload :CLI, "teamocil/cli"
5
5
  end
data/spec/cli_spec.rb ADDED
@@ -0,0 +1,26 @@
1
+ require File.join(File.dirname(__FILE__), "spec_helper.rb")
2
+
3
+ describe Teamocil::CLI do
4
+
5
+ context "executing" do
6
+
7
+ before do # {{{
8
+ @fake_env = { "TMUX" => 1, "HOME" => File.join(File.dirname(__FILE__), "fixtures") }
9
+ end # }}}
10
+
11
+ it "creates a layout" do # {{{
12
+ @cli = Teamocil::CLI.new(["sample"], @fake_env)
13
+ @cli.layout.session.name.should == "sample"
14
+ @cli.layout.session.windows.length.should == 2
15
+ @cli.layout.session.windows.first.name.should == "foo"
16
+ @cli.layout.session.windows.last.name.should == "bar"
17
+ end # }}}
18
+
19
+ it "lists available layouts" do # {{{
20
+ @cli = Teamocil::CLI.new(["--list"], @fake_env)
21
+ @cli.layouts.should == ["sample", "sample-2"]
22
+ end # }}}
23
+
24
+ end
25
+
26
+ end
@@ -0,0 +1,10 @@
1
+ session:
2
+ name: sample-2
3
+ root: ~
4
+ windows:
5
+ - name: "foo"
6
+ splits:
7
+ - cmd: "pwd"
8
+ - name: "bar"
9
+ splits:
10
+ - cmd: "pwd"
@@ -0,0 +1,10 @@
1
+ session:
2
+ name: sample
3
+ root: ~
4
+ windows:
5
+ - name: "foo"
6
+ splits:
7
+ - cmd: "pwd"
8
+ - name: "bar"
9
+ splits:
10
+ - cmd: "pwd"
data/spec/mock/cli.rb ADDED
@@ -0,0 +1,20 @@
1
+ module Teamocil
2
+ module Mock
3
+ module CLI
4
+
5
+ def self.included(base) # {{{
6
+ base.class_eval do
7
+
8
+ # Do not print anything
9
+ def print_layouts
10
+ # Nothing
11
+ end
12
+
13
+ end
14
+ end # }}}
15
+
16
+ end
17
+ end
18
+ end
19
+
20
+ Teamocil::CLI.send :include, Teamocil::Mock::CLI
@@ -0,0 +1,20 @@
1
+ module Teamocil
2
+ module Mock
3
+ module Layout
4
+
5
+ def self.included(base) # {{{
6
+ base.class_eval do
7
+
8
+ # Do not execute anything
9
+ def execute_commands(commands)
10
+ # Nothing
11
+ end
12
+
13
+ end
14
+ end # }}}
15
+
16
+ end
17
+ end
18
+ end
19
+
20
+ Teamocil::Layout.send :include, Teamocil::Mock::Layout
data/spec/spec_helper.rb CHANGED
@@ -2,6 +2,8 @@ $:.unshift File.join(File.dirname(__FILE__), *%w[.. lib])
2
2
 
3
3
  require 'yaml'
4
4
  require 'teamocil'
5
+ require File.join(File.dirname(__FILE__), "./mock/layout.rb")
6
+ require File.join(File.dirname(__FILE__), "./mock/cli.rb")
5
7
 
6
8
  module Helpers
7
9
 
data/teamocil.gemspec CHANGED
@@ -1,4 +1,5 @@
1
- # -*- encoding: utf-8 -*-
1
+ # encoding: utf-8
2
+
2
3
  $:.push File.expand_path("../lib", __FILE__)
3
4
  require "teamocil"
4
5
 
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: teamocil
3
3
  version: !ruby/object:Gem::Version
4
- hash: 19
4
+ hash: 17
5
5
  prerelease:
6
6
  segments:
7
7
  - 0
8
- - 2
9
- - 2
10
- version: 0.2.2
8
+ - 3
9
+ - 1
10
+ version: 0.3.1
11
11
  platform: ruby
12
12
  authors:
13
13
  - "R\xC3\xA9mi Pr\xC3\xA9vost"
@@ -15,11 +15,11 @@ autorequire:
15
15
  bindir: bin
16
16
  cert_chain: []
17
17
 
18
- date: 2011-10-26 00:00:00 Z
18
+ date: 2012-01-21 00:00:00 Z
19
19
  dependencies:
20
20
  - !ruby/object:Gem::Dependency
21
21
  name: rake
22
- prerelease: false
22
+ type: :development
23
23
  version_requirements: &id001 !ruby/object:Gem::Requirement
24
24
  none: false
25
25
  requirements:
@@ -29,11 +29,11 @@ dependencies:
29
29
  segments:
30
30
  - 0
31
31
  version: "0"
32
- type: :development
32
+ prerelease: false
33
33
  requirement: *id001
34
34
  - !ruby/object:Gem::Dependency
35
35
  name: rspec
36
- prerelease: false
36
+ type: :development
37
37
  version_requirements: &id002 !ruby/object:Gem::Requirement
38
38
  none: false
39
39
  requirements:
@@ -43,11 +43,11 @@ dependencies:
43
43
  segments:
44
44
  - 0
45
45
  version: "0"
46
- type: :development
46
+ prerelease: false
47
47
  requirement: *id002
48
48
  - !ruby/object:Gem::Dependency
49
49
  name: yard
50
- prerelease: false
50
+ type: :development
51
51
  version_requirements: &id003 !ruby/object:Gem::Requirement
52
52
  none: false
53
53
  requirements:
@@ -57,11 +57,11 @@ dependencies:
57
57
  segments:
58
58
  - 0
59
59
  version: "0"
60
- type: :development
60
+ prerelease: false
61
61
  requirement: *id003
62
62
  - !ruby/object:Gem::Dependency
63
63
  name: maruku
64
- prerelease: false
64
+ type: :development
65
65
  version_requirements: &id004 !ruby/object:Gem::Requirement
66
66
  none: false
67
67
  requirements:
@@ -71,7 +71,7 @@ dependencies:
71
71
  segments:
72
72
  - 0
73
73
  version: "0"
74
- type: :development
74
+ prerelease: false
75
75
  requirement: *id004
76
76
  description: Teamocil helps you set up window and splits layouts for tmux using YAML configuration files.
77
77
  email: remi@exomel.com
@@ -83,6 +83,7 @@ extra_rdoc_files: []
83
83
 
84
84
  files:
85
85
  - .gitignore
86
+ - .travis.yml
86
87
  - .yardopts
87
88
  - Gemfile
88
89
  - Gemfile.lock
@@ -98,8 +99,13 @@ files:
98
99
  - lib/teamocil.rb
99
100
  - lib/teamocil/cli.rb
100
101
  - lib/teamocil/layout.rb
102
+ - spec/cli_spec.rb
103
+ - spec/fixtures/.teamocil/sample-2.yml
104
+ - spec/fixtures/.teamocil/sample.yml
101
105
  - spec/fixtures/layouts.yml
102
106
  - spec/layout_spec.rb
107
+ - spec/mock/cli.rb
108
+ - spec/mock/layout.rb
103
109
  - spec/spec_helper.rb
104
110
  - teamocil.gemspec
105
111
  homepage: http://github.com/remiprev/teamocil
@@ -136,6 +142,11 @@ signing_key:
136
142
  specification_version: 3
137
143
  summary: Easy window and split layouts for tmux
138
144
  test_files:
145
+ - spec/cli_spec.rb
146
+ - spec/fixtures/.teamocil/sample-2.yml
147
+ - spec/fixtures/.teamocil/sample.yml
139
148
  - spec/fixtures/layouts.yml
140
149
  - spec/layout_spec.rb
150
+ - spec/mock/cli.rb
151
+ - spec/mock/layout.rb
141
152
  - spec/spec_helper.rb