teamocil 0.3.1 → 0.3.2

Sign up to get free protection for your applications and to get access to all the features.
data/LICENSE CHANGED
@@ -1,3 +1,3 @@
1
- Copyright 2011 Rémi Prévost.
1
+ Copyright 2011-2012 Rémi Prévost.
2
2
  You may use this work without restrictions, as long as this notice is included.
3
3
  The work is provided "as is" without warranty of any kind, neither express nor implied.
data/README.md CHANGED
@@ -19,6 +19,7 @@ $ teamocil sample
19
19
  * `--here` opens the session in the current window, it doesn’t create an empty first window.
20
20
  * `--layout` takes a custom file path to a YAML layout file.
21
21
  * `--edit` opens the layout file (whether or not `--layout` is used) with `$EDITOR`.
22
+ * `--list` lists all available layouts.
22
23
 
23
24
  ## Layout file structure
24
25
 
@@ -187,6 +188,7 @@ compctl -g '~/.teamocil/*(:t:r)' teamocil
187
188
  ## Todo list
188
189
 
189
190
  * Making sure the layout is valid before executing it (ie. throw exceptions).
191
+ * Add more specs.
190
192
 
191
193
  ## Contributors
192
194
 
@@ -199,4 +201,4 @@ Take a look at the `spec` folder before you do, and make sure `bundle exec rake
199
201
 
200
202
  ## License
201
203
 
202
- 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.
204
+ Teamocil is © 2011-2012 [Rémi Prévost](http://exomel.com) and may be freely distributed under the [LITL license](http://litl.info/). See the `LICENSE` file.
@@ -0,0 +1,31 @@
1
+ module Teamocil
2
+ class Layout
3
+
4
+ # This class represents a session within tmux
5
+ class Session
6
+ attr_reader :options, :windows, :name
7
+
8
+ # Initialize a new tmux session
9
+ #
10
+ # @param options [Hash] the options, mostly passed by the CLI
11
+ # @param attrs [Hash] the session data from the layout file
12
+ def initialize(options, attrs={}) # {{{
13
+ @name = attrs["name"]
14
+ @windows = attrs["windows"].each_with_index.map { |window, window_index| Window.new(self, window_index, window) }
15
+ @options = options
16
+ end # }}}
17
+
18
+ # Generate commands to send to tmux
19
+ #
20
+ # @return [Array]
21
+ def generate_commands # {{{
22
+ commands = []
23
+ commands << "tmux rename-session \"#{@name}\"" unless @name.nil?
24
+ commands << @windows.map(&:generate_commands)
25
+ commands << "tmux select-pane -t 0"
26
+ commands
27
+ end # }}}
28
+
29
+ end
30
+ end
31
+ end
@@ -0,0 +1,64 @@
1
+ module Teamocil
2
+ class Layout
3
+
4
+ # This class represents a split within a tmux window
5
+ class Split
6
+ attr_reader :width, :height, :cmd, :index, :target
7
+
8
+ # Initialize a new tmux split
9
+ #
10
+ # @param session [Session] the window where the split is initialized
11
+ # @param index [Fixnnum] the split index
12
+ # @param attrs [Hash] the split data from the layout file
13
+ def initialize(window, index, attrs={}) # {{{
14
+ @height = attrs["height"]
15
+ @width = attrs["width"]
16
+ @cmd = attrs["cmd"]
17
+ @target = attrs["target"]
18
+
19
+ @window = window
20
+ @index = index
21
+ end # }}}
22
+
23
+ # Generate commands to send to tmux
24
+ #
25
+ # @return [Array]
26
+ def generate_commands # {{{
27
+ commands = []
28
+
29
+ # Is it a vertical or horizontal split?
30
+ init_command = ""
31
+ unless @index == 0
32
+ if !@width.nil?
33
+ init_command = "tmux split-window -h -p #{@width}"
34
+ elsif !@height.nil?
35
+ init_command = "tmux split-window -p #{@height}"
36
+ else
37
+ init_command = "tmux split-window"
38
+ end
39
+ init_command << " -t #{@target}" unless @target.nil?
40
+ commands << init_command
41
+ end
42
+
43
+ # Wrap all commands around filters
44
+ @cmd = [@window.filters["before"]] + [@cmd] + [@window.filters["after"]]
45
+
46
+ # If a `root` key exist, start each split in this directory
47
+ @cmd.unshift "cd \"#{@window.root}\"" unless @window.root.nil?
48
+
49
+ # Set the TEAMOCIL environment variable
50
+ @cmd.unshift "export TEAMOCIL=1"
51
+
52
+ # Execute each split command
53
+ @cmd.flatten.compact.each do |command|
54
+ commands << "tmux send-keys -t #{@index} \"#{command}\""
55
+ commands << "tmux send-keys -t #{@index} Enter"
56
+ end
57
+
58
+ commands
59
+ end # }}}
60
+
61
+ end
62
+
63
+ end
64
+ end
@@ -0,0 +1,55 @@
1
+ module Teamocil
2
+ class Layout
3
+
4
+ # This class represents a window within tmux
5
+ class Window
6
+ attr_reader :filters, :root, :splits, :options, :index, :name
7
+
8
+ # Initialize a new tmux window
9
+ #
10
+ # @param session [Session] the session where the window is initialized
11
+ # @param index [Fixnnum] the window index
12
+ # @param attrs [Hash] the window data from the layout file
13
+ def initialize(session, index, attrs={}) # {{{
14
+ @name = attrs["name"]
15
+ @root = attrs["root"]
16
+ @options = attrs["options"] || {}
17
+
18
+ @splits = attrs["splits"] || []
19
+ @splits = @splits.each_with_index.map { |split, split_index| Split.new(self, split_index, split) }
20
+
21
+ @filters = attrs["filters"] || {}
22
+ @filters["before"] ||= []
23
+ @filters["after"] ||= []
24
+
25
+ @index = index
26
+ @session = session
27
+ end # }}}
28
+
29
+ # Generate commands to send to tmux
30
+ #
31
+ # @return [Array]
32
+ def generate_commands # {{{
33
+ commands = []
34
+
35
+ if @session.options.include?(:here) and @index == 0
36
+ commands << "tmux rename-window \"#{@name}\""
37
+ else
38
+ commands << "tmux new-window -n \"#{@name}\""
39
+ end
40
+
41
+ commands << @splits.map(&:generate_commands)
42
+
43
+ @options.each_pair do |option, value|
44
+ value = "on" if value === true
45
+ value = "off" if value === false
46
+ commands << "tmux set-window-option #{option} #{value}"
47
+ end
48
+
49
+ commands
50
+ end # }}}
51
+
52
+ end
53
+
54
+ end
55
+ end
@@ -2,140 +2,11 @@ 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
6
-
7
- # This class represents a session within tmux
8
- class Session
9
- attr_reader :options, :windows, :name
10
-
11
- # Initialize a new tmux session
12
- #
13
- # @param options [Hash] the options, mostly passed by the CLI
14
- # @param attrs [Hash] the session data from the layout file
15
- def initialize(options, attrs={}) # {{{
16
- @name = attrs["name"]
17
- @windows = attrs["windows"].each_with_index.map { |window, window_index| Window.new(self, window_index, window) }
18
- @options = options
19
- end # }}}
20
-
21
- # Generate commands to send to tmux
22
- #
23
- # @return [Array]
24
- def generate_commands # {{{
25
- commands = []
26
- commands << "tmux rename-session \"#{@name}\"" unless @name.nil?
27
- commands << @windows.map(&:generate_commands)
28
- commands << "tmux select-pane -t 0"
29
- commands
30
- end # }}}
31
-
32
- end
33
-
34
- # This class represents a window within tmux
35
- class Window
36
- attr_reader :filters, :root, :splits, :options, :index, :name
37
-
38
- # Initialize a new tmux window
39
- #
40
- # @param session [Session] the session where the window is initialized
41
- # @param index [Fixnnum] the window index
42
- # @param attrs [Hash] the window data from the layout file
43
- def initialize(session, index, attrs={}) # {{{
44
- @name = attrs["name"]
45
- @root = attrs["root"]
46
- @options = attrs["options"] || {}
47
-
48
- @splits = attrs["splits"] || []
49
- @splits = @splits.each_with_index.map { |split, split_index| Split.new(self, split_index, split) }
50
-
51
- @filters = attrs["filters"] || {}
52
- @filters["before"] ||= []
53
- @filters["after"] ||= []
54
-
55
- @index = index
56
- @session = session
57
- end # }}}
58
-
59
- # Generate commands to send to tmux
60
- #
61
- # @return [Array]
62
- def generate_commands # {{{
63
- commands = []
64
-
65
- if @session.options.include?(:here) and @index == 0
66
- commands << "tmux rename-window \"#{@name}\""
67
- else
68
- commands << "tmux new-window -n \"#{@name}\""
69
- end
70
-
71
- commands << @splits.map(&:generate_commands)
5
+ autoload :Session, "teamocil/layout/session"
6
+ autoload :Window, "teamocil/layout/window"
7
+ autoload :Split, "teamocil/layout/split"
72
8
 
73
- @options.each_pair do |option, value|
74
- value = "on" if value === true
75
- value = "off" if value === false
76
- commands << "tmux set-window-option #{option} #{value}"
77
- end
78
-
79
- commands
80
- end # }}}
81
-
82
- end
83
-
84
- # This class represents a split within a tmux window
85
- class Split
86
- attr_reader :width, :height, :cmd, :index, :target
87
-
88
- # Initialize a new tmux split
89
- #
90
- # @param session [Session] the window where the split is initialized
91
- # @param index [Fixnnum] the split index
92
- # @param attrs [Hash] the split data from the layout file
93
- def initialize(window, index, attrs={}) # {{{
94
- @height = attrs["height"]
95
- @width = attrs["width"]
96
- @cmd = attrs["cmd"]
97
- @target = attrs["target"]
98
-
99
- @window = window
100
- @index = index
101
- end # }}}
102
-
103
- # Generate commands to send to tmux
104
- #
105
- # @return [Array]
106
- def generate_commands # {{{
107
- commands = []
108
-
109
- # Is it a vertical or horizontal split?
110
- init_command = ""
111
- unless @index == 0
112
- if !@width.nil?
113
- init_command = "tmux split-window -h -p #{@width}"
114
- elsif !@height.nil?
115
- init_command = "tmux split-window -p #{@height}"
116
- else
117
- init_command = "tmux split-window"
118
- end
119
- init_command << " -t #{@target}" unless @target.nil?
120
- commands << init_command
121
- end
122
-
123
- # Wrap all commands around filters
124
- @cmd = [@window.filters["before"]] + [@cmd] + [@window.filters["after"]]
125
-
126
- # If a `root` key exist, start each split in this directory
127
- @cmd.unshift "cd \"#{@window.root}\"" unless @window.root.nil?
128
-
129
- # Execute each split command
130
- @cmd.flatten.compact.each do |command|
131
- commands << "tmux send-keys -t #{@index} \"#{command}\""
132
- commands << "tmux send-keys -t #{@index} Enter"
133
- end
134
-
135
- commands
136
- end # }}}
137
-
138
- end
9
+ attr_reader :session
139
10
 
140
11
  # Initialize a new layout from a hash
141
12
  #
data/lib/teamocil.rb CHANGED
@@ -1,5 +1,5 @@
1
1
  module Teamocil
2
- VERSION = "0.3.1"
2
+ VERSION = "0.3.2"
3
3
  autoload :Layout, "teamocil/layout"
4
4
  autoload :CLI, "teamocil/cli"
5
5
  end
metadata CHANGED
@@ -1,87 +1,68 @@
1
- --- !ruby/object:Gem::Specification
1
+ --- !ruby/object:Gem::Specification
2
2
  name: teamocil
3
- version: !ruby/object:Gem::Version
4
- hash: 17
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.3.2
5
5
  prerelease:
6
- segments:
7
- - 0
8
- - 3
9
- - 1
10
- version: 0.3.1
11
6
  platform: ruby
12
- authors:
13
- - "R\xC3\xA9mi Pr\xC3\xA9vost"
7
+ authors:
8
+ - Rémi Prévost
14
9
  autorequire:
15
10
  bindir: bin
16
11
  cert_chain: []
17
-
18
- date: 2012-01-21 00:00:00 Z
19
- dependencies:
20
- - !ruby/object:Gem::Dependency
12
+ date: 2012-03-05 00:00:00.000000000Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
21
15
  name: rake
22
- type: :development
23
- version_requirements: &id001 !ruby/object:Gem::Requirement
16
+ requirement: &70203537739940 !ruby/object:Gem::Requirement
24
17
  none: false
25
- requirements:
26
- - - ">="
27
- - !ruby/object:Gem::Version
28
- hash: 3
29
- segments:
30
- - 0
31
- version: "0"
18
+ requirements:
19
+ - - ! '>='
20
+ - !ruby/object:Gem::Version
21
+ version: '0'
22
+ type: :development
32
23
  prerelease: false
33
- requirement: *id001
34
- - !ruby/object:Gem::Dependency
24
+ version_requirements: *70203537739940
25
+ - !ruby/object:Gem::Dependency
35
26
  name: rspec
36
- type: :development
37
- version_requirements: &id002 !ruby/object:Gem::Requirement
27
+ requirement: &70203539182320 !ruby/object:Gem::Requirement
38
28
  none: false
39
- requirements:
40
- - - ">="
41
- - !ruby/object:Gem::Version
42
- hash: 3
43
- segments:
44
- - 0
45
- version: "0"
29
+ requirements:
30
+ - - ! '>='
31
+ - !ruby/object:Gem::Version
32
+ version: '0'
33
+ type: :development
46
34
  prerelease: false
47
- requirement: *id002
48
- - !ruby/object:Gem::Dependency
35
+ version_requirements: *70203539182320
36
+ - !ruby/object:Gem::Dependency
49
37
  name: yard
50
- type: :development
51
- version_requirements: &id003 !ruby/object:Gem::Requirement
38
+ requirement: &70203539181900 !ruby/object:Gem::Requirement
52
39
  none: false
53
- requirements:
54
- - - ">="
55
- - !ruby/object:Gem::Version
56
- hash: 3
57
- segments:
58
- - 0
59
- version: "0"
40
+ requirements:
41
+ - - ! '>='
42
+ - !ruby/object:Gem::Version
43
+ version: '0'
44
+ type: :development
60
45
  prerelease: false
61
- requirement: *id003
62
- - !ruby/object:Gem::Dependency
46
+ version_requirements: *70203539181900
47
+ - !ruby/object:Gem::Dependency
63
48
  name: maruku
64
- type: :development
65
- version_requirements: &id004 !ruby/object:Gem::Requirement
49
+ requirement: &70203539181480 !ruby/object:Gem::Requirement
66
50
  none: false
67
- requirements:
68
- - - ">="
69
- - !ruby/object:Gem::Version
70
- hash: 3
71
- segments:
72
- - 0
73
- version: "0"
51
+ requirements:
52
+ - - ! '>='
53
+ - !ruby/object:Gem::Version
54
+ version: '0'
55
+ type: :development
74
56
  prerelease: false
75
- requirement: *id004
76
- description: Teamocil helps you set up window and splits layouts for tmux using YAML configuration files.
57
+ version_requirements: *70203539181480
58
+ description: Teamocil helps you set up window and splits layouts for tmux using YAML
59
+ configuration files.
77
60
  email: remi@exomel.com
78
- executables:
61
+ executables:
79
62
  - teamocil
80
63
  extensions: []
81
-
82
64
  extra_rdoc_files: []
83
-
84
- files:
65
+ files:
85
66
  - .gitignore
86
67
  - .travis.yml
87
68
  - .yardopts
@@ -99,6 +80,9 @@ files:
99
80
  - lib/teamocil.rb
100
81
  - lib/teamocil/cli.rb
101
82
  - lib/teamocil/layout.rb
83
+ - lib/teamocil/layout/session.rb
84
+ - lib/teamocil/layout/split.rb
85
+ - lib/teamocil/layout/window.rb
102
86
  - spec/cli_spec.rb
103
87
  - spec/fixtures/.teamocil/sample-2.yml
104
88
  - spec/fixtures/.teamocil/sample.yml
@@ -110,38 +94,29 @@ files:
110
94
  - teamocil.gemspec
111
95
  homepage: http://github.com/remiprev/teamocil
112
96
  licenses: []
113
-
114
97
  post_install_message:
115
98
  rdoc_options: []
116
-
117
- require_paths:
99
+ require_paths:
118
100
  - lib
119
- required_ruby_version: !ruby/object:Gem::Requirement
101
+ required_ruby_version: !ruby/object:Gem::Requirement
120
102
  none: false
121
- requirements:
122
- - - ">="
123
- - !ruby/object:Gem::Version
124
- hash: 3
125
- segments:
126
- - 0
127
- version: "0"
128
- required_rubygems_version: !ruby/object:Gem::Requirement
103
+ requirements:
104
+ - - ! '>='
105
+ - !ruby/object:Gem::Version
106
+ version: '0'
107
+ required_rubygems_version: !ruby/object:Gem::Requirement
129
108
  none: false
130
- requirements:
131
- - - ">="
132
- - !ruby/object:Gem::Version
133
- hash: 3
134
- segments:
135
- - 0
136
- version: "0"
109
+ requirements:
110
+ - - ! '>='
111
+ - !ruby/object:Gem::Version
112
+ version: '0'
137
113
  requirements: []
138
-
139
114
  rubyforge_project:
140
- rubygems_version: 1.8.6
115
+ rubygems_version: 1.8.10
141
116
  signing_key:
142
117
  specification_version: 3
143
118
  summary: Easy window and split layouts for tmux
144
- test_files:
119
+ test_files:
145
120
  - spec/cli_spec.rb
146
121
  - spec/fixtures/.teamocil/sample-2.yml
147
122
  - spec/fixtures/.teamocil/sample.yml
@@ -150,3 +125,4 @@ test_files:
150
125
  - spec/mock/cli.rb
151
126
  - spec/mock/layout.rb
152
127
  - spec/spec_helper.rb
128
+ has_rdoc: