teamocil 0.1.10 → 0.1.11

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
data/.gitignore ADDED
@@ -0,0 +1,4 @@
1
+ *.gem
2
+ .rvmrc
3
+ .local*
4
+ .yardoc
data/.yardopts ADDED
@@ -0,0 +1,13 @@
1
+ --title "Teamocil"
2
+
3
+ --no-cache
4
+ --protected
5
+ --no-private
6
+
7
+ --markup "markdown"
8
+ --markup-provider "maruku"
9
+
10
+ --format html
11
+
12
+ "README.mkd"
13
+ "lib/**/*.rb"
data/Gemfile ADDED
@@ -0,0 +1,2 @@
1
+ source "http://rubygems.org"
2
+ gemspec
data/Gemfile.lock ADDED
@@ -0,0 +1,32 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ teamocil (0.1.10)
5
+
6
+ GEM
7
+ remote: http://rubygems.org/
8
+ specs:
9
+ diff-lcs (1.1.3)
10
+ maruku (0.6.0)
11
+ syntax (>= 1.0.0)
12
+ rake (0.9.2)
13
+ rspec (2.6.0)
14
+ rspec-core (~> 2.6.0)
15
+ rspec-expectations (~> 2.6.0)
16
+ rspec-mocks (~> 2.6.0)
17
+ rspec-core (2.6.4)
18
+ rspec-expectations (2.6.0)
19
+ diff-lcs (~> 1.1.2)
20
+ rspec-mocks (2.6.0)
21
+ syntax (1.0.0)
22
+ yard (0.7.2)
23
+
24
+ PLATFORMS
25
+ ruby
26
+
27
+ DEPENDENCIES
28
+ maruku
29
+ rake
30
+ rspec
31
+ teamocil!
32
+ yard
data/README.md ADDED
@@ -0,0 +1,189 @@
1
+ # Teamocil
2
+
3
+ Teamocil is a simple tool used to automatically create sessions, windows and splits in [tmux](http://tmux.sourceforge.net/) with YAML files.
4
+
5
+ ## Usage
6
+
7
+ $ gem install teamocil
8
+ $ mkdir ~/.teamocil
9
+ $ teamocil --edit sample
10
+ $ tmux
11
+ $ teamocil sample
12
+
13
+ ## Options
14
+
15
+ * `--here` opens the session in the current window, it doesn’t create an empty first window.
16
+ * `--layout` takes a custom file path to a YAML layout file.
17
+ * `--edit` opens the layout file (whether or not `--layout` is used) with `$EDITOR`.
18
+
19
+ ## Layout file structure
20
+
21
+ A layout file is a single YAML file located in `~/.teamocil` (eg. `~/.teamocil/my-project.yml`).
22
+
23
+ ### Session
24
+
25
+ You can wrap your entire layout file in a `session` and Teamocil will rename the current session (so that you can find it more easily when running `tmux list-sessions`) before creating your windows.
26
+
27
+ #### Keys
28
+
29
+ * `name` (the name of the session)
30
+
31
+ #### Example
32
+
33
+ session:
34
+ name: my-awesome-session
35
+ windows:
36
+ [windows list]
37
+
38
+ ### Windows
39
+
40
+ If you are not using a top-level `session` key, then the first key of your layout file will be `windows`, an array of window items.
41
+
42
+ #### Item keys
43
+
44
+ * `name` (the name that will appear in `tmux` statusbar)
45
+ * `root` (the directory in which every split will be created)
46
+ * `filters` (a hash of `before` and `after` commands to run for each split)
47
+ * `splits` (an array of split items)
48
+ * `options` (a hash of tmux options, see `man tmux` for a list)
49
+
50
+ #### Example
51
+
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]
73
+
74
+ ### Splits
75
+
76
+ Every window must define an array of splits that will be created within it. A vertical or horizontal split will be created, depending on whether the `width` or `height` parameter is used.
77
+
78
+ #### Item keys
79
+
80
+ * `cmd` (the commands to initially execute in the split)
81
+ * `width` (the split width, in percentage)
82
+ * `height` (the split width, in percentage)
83
+ * `target` (the split to set focus on, before creating the current one)
84
+
85
+ #### Example
86
+
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
101
+
102
+ ## Layout examples
103
+
104
+ See more example files in the `examples` directory.
105
+
106
+ ### Simple two splits window
107
+
108
+ #### Content of `~/.teamocil/sample-1.yml`
109
+
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
119
+
120
+ #### Result of `$ teamocil sample-1`
121
+
122
+ .------------------.------------------.
123
+ | (0) | (1) |
124
+ | | |
125
+ | | |
126
+ | | |
127
+ | | |
128
+ | | |
129
+ | | |
130
+ | | |
131
+ | | |
132
+ '------------------'------------------'
133
+
134
+ ### Four tiled splits window
135
+
136
+ #### Content of `~/.teamocil/sample-2.yml`
137
+
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
151
+
152
+ #### Result of `$ teamocil sample-2`
153
+
154
+ .------------------.------------------.
155
+ | (0) | (1) |
156
+ | | |
157
+ | | |
158
+ | | |
159
+ |------------------|------------------|
160
+ | (3) | (2) |
161
+ | | |
162
+ | | |
163
+ | | |
164
+ '------------------'------------------'
165
+
166
+ ## Extras
167
+
168
+ ### Zsh autocompletion
169
+
170
+ To get autocompletion when typing `teamocil <Tab>` in a zsh session, add this line to your `~/.zshrc` file:
171
+
172
+ compctl -g '~/.teamocil/*(:t:r)' teamocil
173
+
174
+ ## Todo list
175
+
176
+ * Support tmux options for windows and splits (eg. `synchronize-panes`)
177
+ * Making sure the layout is valid before executing it
178
+ * Refactor the `Layout` class to make it “test-friendly”
179
+
180
+ ## Contributors
181
+
182
+ Feel free to contribute and submit issues/pull requests [on GitHub](https://github.com/remiprev/teamocil/issues), just like these fine folks did:
183
+
184
+ * Samuel Garneau ([garno](https://github.com/garno))
185
+ * Jimmy Bourassa ([jbourassa](https://github.com/jbourassa))
186
+
187
+ ## License
188
+
189
+ Teamocil is © 2011 [Rémi Prévost](http://exomel.com) and may be freely distributed under the [LITL license](http://litl.info/). See the `LICENSE` file.
data/Rakefile ADDED
@@ -0,0 +1,11 @@
1
+ require "bundler/gem_tasks"
2
+
3
+ desc "Run specs"
4
+ task :spec do # {{{
5
+ sh "bundle exec rspec --color --format=nested #{Dir.glob(File.join(File.dirname(__FILE__), "spec/**/*_spec.rb")).join(" ")}"
6
+ end # }}}
7
+
8
+ desc "Generate documentation"
9
+ task :doc do # {{{
10
+ sh "bundle exec yard doc"
11
+ end # }}}
@@ -0,0 +1,12 @@
1
+ windows:
2
+ - name: simple-four-splits
3
+ splits:
4
+ - cmd: "echo 'first split'"
5
+ - cmd: "echo 'second split'"
6
+ width: 50
7
+ - cmd: "echo 'fourth split'"
8
+ height: 50
9
+ target: bottom-right
10
+ - cmd: "echo 'third split'"
11
+ height: 50
12
+ target: bottom-left
@@ -0,0 +1,12 @@
1
+ windows:
2
+ - name: simple-one-and-three-splits
3
+ splits:
4
+ - cmd: "echo 'first split'"
5
+ - cmd: "echo 'second split'"
6
+ width: 50
7
+ - cmd: "echo 'third split'"
8
+ height: 66
9
+ target: bottom-right
10
+ - cmd: "echo 'fourth split'"
11
+ height: 50
12
+ target: bottom-right
@@ -0,0 +1,18 @@
1
+ windows:
2
+ - name: simple-six-splits
3
+ splits:
4
+ - cmd: "echo 'first split'"
5
+ - cmd: "echo 'second split'"
6
+ width: 50
7
+ - cmd: "echo 'fourth split'"
8
+ height: 66
9
+ target: bottom-right
10
+ - cmd: "echo 'third split'"
11
+ height: 66
12
+ target: bottom-left
13
+ - cmd: "echo 'sixth split'"
14
+ height: 50
15
+ target: bottom-right
16
+ - cmd: "echo 'fifth split'"
17
+ height: 50
18
+ target: bottom-left
@@ -0,0 +1,6 @@
1
+ windows:
2
+ - name: simple-two-horizontal-splits
3
+ splits:
4
+ - cmd: "echo 'first split'"
5
+ - cmd: "echo 'second split'"
6
+ height: 50
@@ -0,0 +1,6 @@
1
+ windows:
2
+ - name: simple-two-vertical-splits
3
+ splits:
4
+ - cmd: "echo 'first split'"
5
+ - cmd: "echo 'second split'"
6
+ width: 50
data/lib/teamocil.rb CHANGED
@@ -1,5 +1,5 @@
1
1
  module Teamocil
2
- VERSION = '0.1.10'
2
+ VERSION = "0.1.11"
3
3
  autoload :Layout, "teamocil/layout"
4
4
  autoload :CLI, "teamocil/cli"
5
5
  end
data/lib/teamocil/cli.rb CHANGED
@@ -24,7 +24,8 @@ module Teamocil
24
24
  system("$EDITOR \"#{file}\"")
25
25
  else
26
26
  bail "There is no file \"#{file}\"" unless File.exists?(file)
27
- layout = Teamocil::Layout.new(file, @options)
27
+ parsed_layout = YAML.load_file(file)
28
+ layout = Teamocil::Layout.new(parsed_layout, @options)
28
29
  layout.to_tmux
29
30
  end
30
31
  end # }}}
@@ -2,12 +2,12 @@ module Teamocil
2
2
  # This class act as a wrapper around a tmux YAML layout file.
3
3
  class Layout
4
4
 
5
- # Initialize a new layout from a file
5
+ # Initialize a new layout from a hash
6
6
  #
7
- # @param file [String] the complete layout file path
8
- # @param options [Hash]
9
- def initialize(file, options) # {{{
10
- @layout = YAML.load_file(file)
7
+ # @param layout [Hash] the parsed layout
8
+ # @param options [Hash] some options
9
+ def initialize(layout, options={}) # {{{
10
+ @layout = layout
11
11
  @options = options
12
12
  end # }}}
13
13
 
@@ -18,9 +18,12 @@ module Teamocil
18
18
  end # }}}
19
19
 
20
20
  # Generate tmux commands based on the data found in the layout file
21
+ #
22
+ # @return [Array] an array of shell commands to send
21
23
  def generate_commands # {{{
22
24
  output = []
23
25
 
26
+ # Support renaming of current session
24
27
  if @layout["session"].nil?
25
28
  windows = @layout["windows"]
26
29
  else
@@ -37,16 +40,15 @@ module Teamocil
37
40
  output << "tmux new-window -n \"#{window["name"]}\""
38
41
  end
39
42
 
40
- # Make sure our filters return arrays
43
+ # Make sure we have all the keys we need
44
+ window["options"] ||= {}
41
45
  window["filters"] ||= {}
42
46
  window["filters"]["before"] ||= []
43
47
  window["filters"]["after"] ||= []
44
- window["filters"]["before"] = [window["filters"]["before"]] unless window["filters"]["before"].is_a? Array
45
- window["filters"]["after"] = [window["filters"]["after"]] unless window["filters"]["after"].is_a? Array
46
48
 
47
49
  # Create splits
48
- window["splits"].each_with_index do |split, index|
49
- unless index == 0
50
+ window["splits"].each_with_index do |split, split_index|
51
+ unless split_index == 0
50
52
  if split.include?("width")
51
53
  cmd = "tmux split-window -h -p #{split["width"]}"
52
54
  elsif split.include?("height")
@@ -58,24 +60,29 @@ module Teamocil
58
60
  output << cmd
59
61
  end
60
62
 
61
- # Support single command splits, but treat it as an array nevertheless
62
- split["cmd"] = [split["cmd"]] unless split["cmd"].is_a? Array
63
-
64
63
  # Wrap all commands around filters
65
- split["cmd"] = window["filters"]["before"] + split["cmd"] + window["filters"]["after"]
64
+ split["cmd"] = [window["filters"]["before"]] + [split["cmd"]] + [window["filters"]["after"]]
66
65
 
67
66
  # If a `root` key exist, start each split in this directory
68
- split["cmd"] = ["cd \"#{window["root"]}\""] + split["cmd"] if window.include?("root")
67
+ split["cmd"].unshift "cd \"#{window["root"]}\"" if window.include?("root")
69
68
 
70
69
  # Execute each split command
71
- split["cmd"].compact.each do |command|
72
- output << "tmux send-keys -t #{index} \"#{command}\""
73
- output << "tmux send-keys -t #{index} Enter"
70
+ split["cmd"].flatten.compact.each do |command|
71
+ output << "tmux send-keys -t #{split_index} \"#{command}\""
72
+ output << "tmux send-keys -t #{split_index} Enter"
74
73
  end
75
74
  end
76
75
 
76
+ # Set tmux options
77
+ window["options"].each_pair do |option, value|
78
+ value = "on" if value === true
79
+ value = "off" if value === false
80
+ output << "tmux set-window-option #{option} #{value}"
81
+ end
82
+
77
83
  end
78
84
 
85
+ # Set the focus in the first split
79
86
  output << "tmux select-pane -t 0"
80
87
  end # }}}
81
88
 
@@ -0,0 +1,13 @@
1
+ # Simple two windows layout
2
+ two-windows:
3
+ windows:
4
+ - name: "foo"
5
+ splits:
6
+ - cmd: "echo 'foo'"
7
+ - cmd: "echo 'foo again'"
8
+ width: 50
9
+ - name: "bar"
10
+ splits:
11
+ - cmd: "echo 'bar'"
12
+ - cmd: "echo 'bar again'"
13
+ width: 50
@@ -0,0 +1,13 @@
1
+ require File.join(File.dirname(__FILE__), "spec_helper.rb")
2
+
3
+ describe Teamocil::Layout do
4
+ context "initializing" do
5
+
6
+ it "create two windows" do # {{{
7
+ layout = Teamocil::Layout.new(layouts["two-windows"], {})
8
+ commands = layout.generate_commands
9
+ commands.grep(/new-window/).length.should be 2
10
+ end # }}}
11
+
12
+ end
13
+ end
@@ -0,0 +1,17 @@
1
+ $:.unshift File.join(File.dirname(__FILE__), *%w[.. lib])
2
+
3
+ require 'yaml'
4
+ require 'teamocil'
5
+
6
+ module Helpers
7
+
8
+ def layouts # {{{
9
+ return @@examples if defined?(@@examples)
10
+ @@examples = YAML.load_file(File.join(File.dirname(__FILE__), "fixtures/layouts.yml"))
11
+ end # }}}
12
+
13
+ end
14
+
15
+ RSpec.configure do |c|
16
+ c.include Helpers
17
+ end
data/teamocil.gemspec ADDED
@@ -0,0 +1,28 @@
1
+ # -*- encoding: utf-8 -*-
2
+ $:.push File.expand_path("../lib", __FILE__)
3
+ require "teamocil"
4
+
5
+ spec = Gem::Specification.new do |s|
6
+ # Metadata
7
+ s.name = "teamocil"
8
+ s.version = Teamocil::VERSION
9
+ s.platform = Gem::Platform::RUBY
10
+ s.authors = "Rémi Prévost"
11
+ s.email = "remi@exomel.com"
12
+ s.homepage = "http://github.com/remiprev/teamocil"
13
+ s.summary = "Easy window and split layouts for tmux"
14
+ s.description = "Teamocil helps you set up window and splits layouts for tmux using YAML configuration files."
15
+
16
+ # Manifest
17
+ s.files = `git ls-files`.split("\n")
18
+ s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
19
+ s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
20
+ s.require_paths = ["lib"]
21
+
22
+ # Dependencies
23
+ s.add_development_dependency "rake"
24
+ s.add_development_dependency "rspec"
25
+ s.add_development_dependency "yard"
26
+ s.add_development_dependency "maruku"
27
+
28
+ end
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: 15
4
+ hash: 13
5
5
  prerelease:
6
6
  segments:
7
7
  - 0
8
8
  - 1
9
- - 10
10
- version: 0.1.10
9
+ - 11
10
+ version: 0.1.11
11
11
  platform: ruby
12
12
  authors:
13
13
  - "R\xC3\xA9mi Pr\xC3\xA9vost"
@@ -15,9 +15,64 @@ autorequire:
15
15
  bindir: bin
16
16
  cert_chain: []
17
17
 
18
- date: 2011-10-08 00:00:00 Z
19
- dependencies: []
20
-
18
+ date: 2011-10-20 00:00:00 Z
19
+ dependencies:
20
+ - !ruby/object:Gem::Dependency
21
+ name: rake
22
+ prerelease: false
23
+ requirement: &id001 !ruby/object:Gem::Requirement
24
+ none: false
25
+ requirements:
26
+ - - ">="
27
+ - !ruby/object:Gem::Version
28
+ hash: 3
29
+ segments:
30
+ - 0
31
+ version: "0"
32
+ type: :development
33
+ version_requirements: *id001
34
+ - !ruby/object:Gem::Dependency
35
+ name: rspec
36
+ prerelease: false
37
+ requirement: &id002 !ruby/object:Gem::Requirement
38
+ none: false
39
+ requirements:
40
+ - - ">="
41
+ - !ruby/object:Gem::Version
42
+ hash: 3
43
+ segments:
44
+ - 0
45
+ version: "0"
46
+ type: :development
47
+ version_requirements: *id002
48
+ - !ruby/object:Gem::Dependency
49
+ name: yard
50
+ prerelease: false
51
+ requirement: &id003 !ruby/object:Gem::Requirement
52
+ none: false
53
+ requirements:
54
+ - - ">="
55
+ - !ruby/object:Gem::Version
56
+ hash: 3
57
+ segments:
58
+ - 0
59
+ version: "0"
60
+ type: :development
61
+ version_requirements: *id003
62
+ - !ruby/object:Gem::Dependency
63
+ name: maruku
64
+ prerelease: false
65
+ requirement: &id004 !ruby/object:Gem::Requirement
66
+ none: false
67
+ requirements:
68
+ - - ">="
69
+ - !ruby/object:Gem::Version
70
+ hash: 3
71
+ segments:
72
+ - 0
73
+ version: "0"
74
+ type: :development
75
+ version_requirements: *id004
21
76
  description: Teamocil helps you set up window and splits layouts for tmux using YAML configuration files.
22
77
  email: remi@exomel.com
23
78
  executables:
@@ -27,11 +82,26 @@ extensions: []
27
82
  extra_rdoc_files: []
28
83
 
29
84
  files:
30
- - lib/teamocil/cli.rb
31
- - lib/teamocil/layout.rb
32
- - lib/teamocil.rb
85
+ - .gitignore
86
+ - .yardopts
87
+ - Gemfile
88
+ - Gemfile.lock
33
89
  - LICENSE
90
+ - README.md
91
+ - Rakefile
34
92
  - bin/teamocil
93
+ - examples/simple-four-splits.yml
94
+ - examples/simple-one-and-three-splits.yml
95
+ - examples/simple-six-splits.yml
96
+ - examples/simple-two-horitonzal-splits.yml
97
+ - examples/simple-two-vertical-splits.yml
98
+ - lib/teamocil.rb
99
+ - lib/teamocil/cli.rb
100
+ - lib/teamocil/layout.rb
101
+ - spec/fixtures/layouts.yml
102
+ - spec/layout_spec.rb
103
+ - spec/spec_helper.rb
104
+ - teamocil.gemspec
35
105
  homepage: http://github.com/remiprev/teamocil
36
106
  licenses: []
37
107
 
@@ -65,5 +135,7 @@ rubygems_version: 1.8.6
65
135
  signing_key:
66
136
  specification_version: 3
67
137
  summary: Easy window and split layouts for tmux
68
- test_files: []
69
-
138
+ test_files:
139
+ - spec/fixtures/layouts.yml
140
+ - spec/layout_spec.rb
141
+ - spec/spec_helper.rb